cloud_elements_connector 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/cloud_elements_connector.rb +102 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dcd275ca604064d7af0fff7082c4f75d88591c95
|
4
|
+
data.tar.gz: f10b4523ecba39715e2548fe8fee826b7accfd00
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 88cc49e397410fdb24726a4a5e1231a92d470c7cb365bc3c04b89f53a0b5494a95f3b322c5201ae73b2c7e4f2be76f7be7d9f6c8c9b9ad231937cd412e339250
|
7
|
+
data.tar.gz: 779a250c3523e3bd620b2df5b52c936a7c2a0e716d463d87eec0e7d949f737ef9f05067d7c682ce5a78c8bc2c1bde944f2a24ecf48c2c4f8bd9b505a162154e1
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'httmultiparty'
|
2
|
+
|
3
|
+
class APIException < Exception
|
4
|
+
end
|
5
|
+
|
6
|
+
class CloudElementsConnector
|
7
|
+
|
8
|
+
=begin
|
9
|
+
Class that allows connection to the Cloud Elements API.
|
10
|
+
All connections are made through the invoke method.
|
11
|
+
It utilized HTTMultiParty to make http requests.
|
12
|
+
=end
|
13
|
+
class ElementsConnector
|
14
|
+
|
15
|
+
attr_accessor :api_endpoint
|
16
|
+
|
17
|
+
def initialize(api_endpoint='https://console.cloud-elements.com/elements/api-v1')
|
18
|
+
@api_endpoint = api_endpoint # Endpoint to hit the api. Defaults to production
|
19
|
+
@headers = Hash.new # Headers for some requests
|
20
|
+
@headers['Content-Type'] = 'application-json'
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def process_request
|
26
|
+
# This will do error handling later
|
27
|
+
end
|
28
|
+
|
29
|
+
public
|
30
|
+
|
31
|
+
# This method conducts the http request and send back the response.
|
32
|
+
# It received a string containing the http method, a hash of query/body parameters
|
33
|
+
# and and optional list of file names for requests that deal with posting files.
|
34
|
+
def request(httpMethod, params, files)
|
35
|
+
case httpMethod
|
36
|
+
when 'get' then response = HTTMultiParty.get(@url, :headers => @headers, :query => params)
|
37
|
+
when 'post'
|
38
|
+
if files
|
39
|
+
files.each { |f| params[f] = File.new(f) }
|
40
|
+
@headers.delete(['Content-Type'])
|
41
|
+
response = HTTMultiParty.post(@url, :headers => @headers, :query => params)
|
42
|
+
@headers['Content-Type'] = 'application-json'
|
43
|
+
else
|
44
|
+
response = HTTMultiParty.post(@url, :headers => @headers, :body => params.to_json)
|
45
|
+
end
|
46
|
+
when 'put' then response = HTTMultiParty.put(@url, :headers => @headers, :body => params.to_json)
|
47
|
+
when 'delete' then response = HTTMultiParty.delete(@url, :headers => @headers, :body => params.to_json)
|
48
|
+
end
|
49
|
+
|
50
|
+
return response
|
51
|
+
end
|
52
|
+
|
53
|
+
# This method allows users to interact with the Elements API.
|
54
|
+
# It is essentially a copy of the Java ElementsConnector class.
|
55
|
+
def invoke(httpMethod, providerName, headers, apiMethodName, params=nil, files=nil, providerVersion='1')
|
56
|
+
@url = "#{@api_endpoint}/#{providerName}/#{providerVersion}/#{apiMethodName}"
|
57
|
+
if headers.class() == Hash
|
58
|
+
auth_string = "User #{headers[:user_secret]}, Organization #{headers[:organization_secret]}"
|
59
|
+
else
|
60
|
+
auth_string = "Element #{headers}"
|
61
|
+
end
|
62
|
+
@headers['Authorization'] = auth_string
|
63
|
+
|
64
|
+
return request(httpMethod, params, files)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def initialize(providerName, elementToken, base_url='https://console.cloud-elements.com/elements/api-v1/')
|
70
|
+
apidocs = HTTMultiParty.get(base_url+providerName)
|
71
|
+
if apidocs.has_key? 'errorMsg'
|
72
|
+
raise APIException.new "Element Hub for #{providerName} does not exist"
|
73
|
+
end
|
74
|
+
|
75
|
+
method_data = []
|
76
|
+
method_count = 0
|
77
|
+
apidocs['apis'].each do |api|
|
78
|
+
method_data[method_count] = Hash.new
|
79
|
+
|
80
|
+
method_data[method_count][:elementToken] = elementToken
|
81
|
+
method_data[method_count][:providerName] = providerName
|
82
|
+
|
83
|
+
method_data[method_count][:apiMethodName] = api['path'].split('/')[-1]
|
84
|
+
method_data[method_count][:httpMethod] = api['operations'][0]["httpMethod"].downcase()
|
85
|
+
method_count = method_count + 1
|
86
|
+
end
|
87
|
+
|
88
|
+
method_data.each do |data|
|
89
|
+
define_singleton_method data[:apiMethodName] do |params=nil, files=nil|
|
90
|
+
client = ElementsConnector.new
|
91
|
+
return client.invoke(data[:httpMethod], data[:providerName], data[:elementToken], data[:apiMethodName], params, files)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
if self.respond_to? :ping
|
96
|
+
response = self.ping
|
97
|
+
if not response['success']
|
98
|
+
raise APIException.new response['errorMsg']
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloud_elements_connector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Rodriguez
|
8
|
+
- Josh Wyse
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httmultiparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.3.10
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.3.10
|
28
|
+
description: Cloud Elements Connector. Allows you to interact with the Cloud Elements
|
29
|
+
API. More info on the API at cloud-elements.com
|
30
|
+
email: christian.etpr10@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/cloud_elements_connector.rb
|
36
|
+
homepage: https://github.com/cloud-elements/elements-connector-ruby
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.2.2
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Cloud Elements Connector
|
60
|
+
test_files: []
|