cloud_elements 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/cloud_elements.rb +48 -0
  3. metadata +57 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 231611e5d7a20b637a7e3a3528d91a207864df93
4
+ data.tar.gz: 7ace83cf907560235ecb3efd1e175dd1f77e1dea
5
+ SHA512:
6
+ metadata.gz: f388bb6c02eac4915a309cd9f327faecee6af8495579e9c9bb2a6527afcc2d1aab9c2e76cfd8b5b199e2c25205299e058df4c28bd63056cafdf605f06475e569
7
+ data.tar.gz: e44a3c559e58d4a4e26b9e597c43e1804d1a5f97faa52110227019c69aa903b54a72b63eb65d18918e7e0842eeed8f0eb17f3b48e22f747961b8fcf878e76e68
@@ -0,0 +1,48 @@
1
+ require 'httmultiparty'
2
+
3
+ =begin
4
+ Class that allows connection to the Cloud Elements REST API.
5
+ All connections are made through the invoke method.
6
+ It utilized HTTMultiParty to make http requests.
7
+ =end
8
+ class CloudElements
9
+ def initialize(api_endpoint='https://console.cloud-elements.com/elements/api-v1')
10
+ @api_endpoint = api_endpoint # Endpoint to hit the api. Defaults to production
11
+ @headers = Hash.new # Headers for some requests
12
+ end
13
+
14
+ private
15
+
16
+ def process_request
17
+ # This will do error handling later
18
+ end
19
+
20
+ public
21
+
22
+ # This method conducts the http request and send back the response.
23
+ # It received a string containing the http method, a hash of query/body parameters
24
+ # and and optional list of file names for requests that deal with posting files.
25
+ def request(httpMethod, params, files)
26
+ case httpMethod
27
+ when 'get' then response = HTTMultiParty.get(@url, :headers => @headers, :query => params)
28
+ when 'post'
29
+ if files
30
+ files.each { |f| params[f] = File.new(f) }
31
+ response = HTTMultiParty.post(@url, :headers => @headers, :query => params)
32
+ else
33
+ response = HTTMultiParty.post(@url, :headers => @headers, :body => params.to_json)
34
+ end
35
+ when 'put' then response = HTTMultiParty.put(@url, :headers => @headers, :body => params.to_json)
36
+ when 'delete' then response = HTTMultiParty.delete(@url, :headers => @headers, :body => params.to_json)
37
+ end
38
+ return response
39
+ end
40
+
41
+ # This method allows users to interact with the Elements API.
42
+ # It is essentially a copy of the Java ElementsConnector class.
43
+ def invoke(httpMethod, providerName, elementToken, apiMethodName, params=nil, files=nil, providerVersion='1')
44
+ @url = "#{@api_endpoint}/#{providerName}/#{providerVersion}/#{apiMethodName}"
45
+ @headers['Authorization'] = "Element #{elementToken}"
46
+ return request(httpMethod, params, files)
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloud_elements
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ platform: ruby
6
+ authors:
7
+ - Christian Rodriguez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2012-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httmultiparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.10
27
+ description: Ruby wrapper around the Cloud Elements API
28
+ email: christian.etpr10@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/cloud_elements.rb
34
+ homepage:
35
+ licenses: []
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.2.0
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Cloud Elements ruby api
57
+ test_files: []