usabilla_api 0.0.1 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/usabilla_api.rb +16 -97
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88b288cbe2a7e43ed1477c763db86aceee16180c
|
4
|
+
data.tar.gz: 76b7f129876ad1399addd376afa6e0b8665b29e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06af446296d47cea9bf84cc2edf7ed716cd97aca470702b4bf48cc0730016a11321c13659d35eaf270ae7af283f318bb8df1ca35473dbfea82fb3cdd0a6b6047
|
7
|
+
data.tar.gz: 74173951d8452543d72d890393de2100eccad99bf486150fc1f6bd5fbd573c852443da52b0722ce93c42cc23686ae63a520b95527d36dfda0e10701a59bbc27a
|
data/lib/usabilla_api.rb
CHANGED
@@ -1,104 +1,23 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'usabilla_api/config'
|
2
|
+
require 'usabilla_api/convenience'
|
3
|
+
require 'usabilla_api/usabilla_api'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
class APIClient
|
8
|
-
attr_accessor :method, :host, :host_protocol, :query_parameters, :credentials
|
9
|
-
|
10
|
-
def initialize(client_key, secret_key, params)
|
11
|
-
@method = 'GET'
|
12
|
-
@host = 'data.usabilla.com'
|
13
|
-
@host_protocol = 'https://'
|
14
|
-
@query_parameters = params
|
15
|
-
@credentials = Usabilla::Credentials.new(client_key, secret_key)
|
16
|
-
end
|
17
|
-
|
18
|
-
def get_signature_key(key, long_date)
|
19
|
-
k_date = OpenSSL::HMAC.digest('sha256', 'USBL1' + key, long_date)
|
20
|
-
k_signing = OpenSSL::HMAC.digest('sha256', k_date, 'usbl1_request')
|
21
|
-
k_signing
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
def set_query_parameters(params)
|
26
|
-
@query_parameters = params
|
27
|
-
end
|
28
|
-
|
29
|
-
def get_query_parameters
|
30
|
-
@query_parameters
|
31
|
-
end
|
32
|
-
|
33
|
-
def send_signed_request(scope)
|
34
|
-
|
35
|
-
if @credentials.client_key.nil? || @credentials.secret_key.nil?
|
36
|
-
raise 'Invalid Access Key. The Access Key supplied is invalid.'
|
37
|
-
end
|
38
|
-
|
39
|
-
t = DateTime.now
|
40
|
-
usbldate = t.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
41
|
-
datestamp = t.strftime('%Y%m%d') # Date w/o time, used in credential scope
|
42
|
-
long_date = t.strftime('%Y%m%dT%H%M%SZ')
|
43
|
-
|
44
|
-
canonical_uri = scope
|
45
|
-
canonical_querystring = get_query_parameters
|
46
|
-
canonical_headers = "date:#{usbldate}\nhost:#{@host}\n"
|
47
|
-
signed_headers = 'date;host'
|
48
|
-
payload_hash = OpenSSL::Digest::SHA256.new.hexdigest
|
49
|
-
|
50
|
-
canonical_request = "#{@method}\n#{canonical_uri}\n#{canonical_querystring}\n#{canonical_headers}\n#{signed_headers}\n#{payload_hash}"
|
51
|
-
|
52
|
-
canonical_request_digest = OpenSSL::Digest::SHA256.new(canonical_request).hexdigest
|
53
|
-
algorithm = 'USBL1-HMAC-SHA256'
|
54
|
-
credential_scope = "#{datestamp}/usbl1_request"
|
55
|
-
|
56
|
-
string_to_sign = "#{algorithm}\n#{long_date}\n#{credential_scope}\n#{canonical_request_digest}"
|
57
|
-
|
58
|
-
signing_key = get_signature_key(@credentials.secret_key, datestamp)
|
59
|
-
signature = OpenSSL::HMAC.hexdigest('sha256', signing_key, string_to_sign)
|
60
|
-
|
61
|
-
authorization_header = "#{algorithm} Credential=#{@credentials.client_key}/#{credential_scope}, SignedHeaders=#{signed_headers}, Signature=#{signature}"
|
62
|
-
headers = {'date' => usbldate, 'Authorization' => authorization_header}
|
63
|
-
|
64
|
-
# Send the request.
|
65
|
-
request_url = @host + scope + '?' + canonical_querystring
|
66
|
-
response = RestClient.get(@host_protocol + request_url, headers)
|
67
|
-
print "#{request_url}"
|
68
|
-
response
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
def get_buttons
|
73
|
-
send_signed_request('/live/website/button')
|
74
|
-
end
|
75
|
-
|
76
|
-
def get_feedback_items(button_id='%2A')
|
77
|
-
if button_id.nil? || button_id.empty?
|
78
|
-
raise 'Invalid button ID'
|
79
|
-
end
|
80
|
-
if button_id == '*'
|
81
|
-
button_id = '%2A'
|
82
|
-
end
|
83
|
-
feedback_items = send_signed_request("/live/website/button/#{button_id}/feedback")
|
84
|
-
feedback_items
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
def get_campaigns
|
89
|
-
send_signed_request('/live/website/campaign')
|
90
|
-
end
|
91
|
-
|
92
|
-
def get_campaign_results(campaign_id=nil)
|
5
|
+
def require_directory(relative_path)
|
6
|
+
Dir[File.dirname(__FILE__) + relative_path].each { |file| require file }
|
7
|
+
end
|
93
8
|
|
94
|
-
|
95
|
-
|
96
|
-
end
|
9
|
+
%w(/usabilla_api/clients/**/*.rb /usabilla_api/models/**.rb
|
10
|
+
/usabilla_api/models/**/*.rb).each { |path| require_directory path }
|
97
11
|
|
98
|
-
|
99
|
-
|
12
|
+
module UsabillaApi
|
13
|
+
extend Convenience::ClassMethods
|
100
14
|
|
101
|
-
|
15
|
+
def self.configure
|
16
|
+
yield configuration
|
17
|
+
end
|
102
18
|
|
19
|
+
def self.configuration
|
20
|
+
@configuration ||= UsabillaApi::Config.new
|
21
|
+
@configuration
|
103
22
|
end
|
104
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usabilla_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Molinaro
|
@@ -9,7 +9,41 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-03-19 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.7.7
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.7'
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.7.7
|
13
47
|
description: A Ruby Usabilla API Gem that will allow you to connect to and use the
|
14
48
|
Usabilla API
|
15
49
|
email: Teirson@gmail.com
|