getfivestars_api 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ require 'digest'
2
+
3
+ module GetFiveStars
4
+ module Api
5
+ class AuthToken
6
+ def initialize(client_id, private_key)
7
+ @client_id = client_id
8
+ @private_key = private_key
9
+ end
10
+
11
+ def sign_request(request)
12
+ request.set('clientId', @client_id)
13
+ token = ""
14
+ request.get_parameters.sort.map do |key,value|
15
+ token += key + value
16
+ end
17
+ request.set('hash', Digest::SHA256.hexdigest(@private_key + token))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module GetFiveStars
5
+ module Api
6
+ class NetClient
7
+ def initialize(request)
8
+ @request = request
9
+ end
10
+
11
+ def send_request
12
+ req = Net::HTTP::Post.new("/api" + @request.get_action, initheader = {'Content-Type' =>'application/json'})
13
+ req.body = @request.get_parameters.to_json
14
+ http = Net::HTTP.new("getfivestars.com", 443)
15
+ http.use_ssl = true
16
+ response = http.start {|http| http.request(req) }
17
+ GetFiveStars::Api::Response.new(JSON.parse(response.body))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ module GetFiveStars
2
+ module Api
3
+ class Request
4
+ def initialize(action, request)
5
+ @action = action
6
+ @request = request
7
+ end
8
+
9
+ def set(key, val)
10
+ @request[key] = val
11
+ end
12
+
13
+ def get(key)
14
+ if @request.include?(key)
15
+ @request[key]
16
+ else
17
+ ""
18
+ end
19
+ end
20
+
21
+ def get_parameters()
22
+ @request
23
+ end
24
+
25
+ def get_action()
26
+ @action
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,36 @@
1
+ module GetFiveStars
2
+ module Api
3
+ class Response
4
+ def initialize(response)
5
+ if(not response.include?("errorCode") or not response.include?("errorMessage"))
6
+ response["errorCode"] = "-1"
7
+ response["errorMessage"] = "Unknown error"
8
+ end
9
+
10
+ @error_code = response["errorCode"]
11
+ @error_message = response["errorMessage"]
12
+
13
+ response.delete("errorCode")
14
+ response.delete("errorMessage")
15
+
16
+ @response = response
17
+ end
18
+
19
+ def get_status
20
+ self.get_error_code == 0
21
+ end
22
+
23
+ def get_error_code
24
+ @error_code
25
+ end
26
+
27
+ def get_error_message
28
+ @error_message
29
+ end
30
+
31
+ def get_response
32
+ @response
33
+ end
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: getfivestars_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - GetFiveStars
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-12-22 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: GetFiveStars SDK
15
+ email: support@getfivestars.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - getfivestars/api/net_client.rb
21
+ - getfivestars/api/response.rb
22
+ - getfivestars/api/request.rb
23
+ - getfivestars/api/auth_token.rb
24
+ homepage: https://www.getfivestars.com
25
+ licenses:
26
+ - MIT
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.23
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: SDK
49
+ test_files: []