Giter Site home page Giter Site logo

gcloudex's Introduction

Build Status

GCloudex

Google Cloud for Elixir. Friendly set of wrappers for Google Cloud Platform services' API's.

Features

  • Minimal configuration and dependencies
  • Friendly way to use Google Cloud services' API's
  • Function names and signatures closely mimic their REST counterparts
  • HTTP requests sent using the popular HTTPoison app providing familiar HTTP responses
  • Easy to extend

Installation and Configuration

GCloudex uses HTTPoison for the HTTP requests, Poison for JSON encoding/decoding and Friendly for XML parsing. The Google Authorization Tokens are retrieved using Goth. The JSON API's for the various Google Cloud services are used whenever possible or available.

  1. Add gcloudex to your list of dependencies in mix.exs:

    def deps do
      [{:gcloudex, git: "[email protected]:sashaafm/gcloudex.git"}]
    end
    
  2. Ensure gcloudex is started before your application:

    def application do
      [applications: [:gcloudex]]
    end
    

Then go to the Google Cloud's website and download the credentials file for your Google Project.

Put that file in your application's config folder and rename the file to creds.json (or whatever name you prefer). This file will be used to authenticate the requests. Be sure to add it to your .gitignore file in case you're uploading to a public repository.

Finally put inside the config file you want (like dev.exs) the following line:

config :goth,
  json: "config/<filename>.json" |> Path.expand |> File.read!

That's all you need to use GCloudex.

Usages Examples

Cloud Storage:

GCloudex.CloudStorage.Client.list_buckets # => {:ok, %HTTPoison.Response{body: ..., status_code: 200}}
GCloudex.CloudStorage.CLient.put_object "bucket_name", "this_file.txt" # => {:ok, %HTTPoison.Response{body: ..., status_code: 200}}

Cloud SQL:

GCloudex.CloudSQL.Client.list_databases "instance_name" # => {:ok, %HTTPoison.Response{body: ...,status_code: 200}}
GCloudex.CloudSQL.Client-insert_databaes "instance_name", "db_name" # => {:ok, %HTTPoison.Response{body: ...,status_code: 200}}

Cloud Speech:

body = """
{
  "audio": {
    "uri": "gs://foo/bar.flac"
  },
  "config": {
    "encoding":"flac",
    "sampleRate": 48000,
    "languageCode":"en-US",
    "maxAlternatives": 1
  }
}
"""

iex> GCloudex.CloudSpeech.Client.longrunningrecognize(body)
{:ok,
 %HTTPoison.Response{body: "{\n  \"name\": \"1234567890\"\n}\n",
  headers: [...], status_code: 200}}

iex> GCloudex.CloudSpeech.Client.get("1234567890")
{:ok,
 %HTTPoison.Response{body: "{\n  \"name\": \"1234567890\",\n  \"metadata\": {...

Roadmap

  • Google Cloud Storage
  • Google Cloud SQL
  • Google Compute Engine
  • Google Cloud Speech API (partial)
  • Google Cloud Datastore

gcloudex's People

Contributors

alexebird avatar henry-hz avatar kristianfreeman avatar sashaafm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gcloudex's Issues

Custom HTTPoison timeout

Hey,

it would be nice if we could set a custom HTTPoison timeout. I send some bigger files and always get the timeout.

Compilation error

Hey, when I try to use this library as a dependency it is failing to compile, I get the following message:

== Compilation error on file lib/compute_engine/machine_types.ex ==
** (ArgumentError) argument error
    :erlang.iolist_to_binary(nil)
    lib/poison/parser.ex:35: Poison.Parser.parse/2
    lib/poison/parser.ex:50: Poison.Parser.parse!/2
    lib/poison.ex:83: Poison.decode!/2
    lib/gcloudex.ex:14: GCloudex.get_project_id/0
    lib/compute_engine/machine_types.ex:2: (module)

I tried with Elixir 1.2.3 and Erlang/OTP 18 [erts-7.3].

Don't require :goth :json config to be present at compile time

I'm using this goth branch, which looks like it might be merged soonish: peburrows/goth#6

This doesn't require the :goth :json to be set at all, as it can be discovered.

However, right now if :json is not set, gcloudex doesn't compile:

==> gcloudex
Compiling 11 files (.ex)

== Compilation error on file lib/cloud_storage/client.ex ==
** (ArgumentError) argument error
    :erlang.iolist_to_binary(nil)
    lib/poison/parser.ex:35: Poison.Parser.parse/2
    lib/poison/parser.ex:50: Poison.Parser.parse!/2
    lib/poison.ex:83: Poison.decode!/2
    lib/gcloudex.ex:14: GCloudex.get_project_id/0
    lib/cloud_storage/client.ex:2: (module)

could not compile dependency :gcloudex, "mix compile" failed. You can recompile this dependency with "mix deps.compile gcloudex", update it with "mix deps.update gcloudex" or clean it with "mix deps.clean gcloudex"```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.