hubble_observatory 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +8 -0
- data/hubble_observatory.gemspec +2 -2
- data/lib/hubble_observatory/fs_employee.rb +14 -0
- data/lib/hubble_observatory/request.rb +36 -14
- data/lib/hubble_observatory/talent_account.rb +8 -8
- data/lib/hubble_observatory/version.rb +1 -1
- data/lib/hubble_observatory.rb +1 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f06b9d11add7467d2c7e71ef80ec058425eab3e
|
4
|
+
data.tar.gz: 87f023ed808ea3c9b7251a7d72d8b6472491751f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8903f5084cbf6394de3f63dd90d0885f976fcfc7e6a6f172ca1f254780f78092ebea987855fb00fad3f728cc64c009e7fa2e6618a5dd1cc2929a41e3e238f7e3
|
7
|
+
data.tar.gz: 665e0b018980a3271e652fb45e92f5264b5e8f5cb2b5b71e6001da48d9e84591788a5a35786f829c21cbfa5540ce82654e5cace509c780c42f05ce1105b45816
|
data/CHANGELOG.md
CHANGED
@@ -6,7 +6,11 @@ For more information about changelogs, check
|
|
6
6
|
[Keep a Changelog](http://keepachangelog.com) and
|
7
7
|
[Vandamme](http://tech-angels.github.io/vandamme).
|
8
8
|
|
9
|
-
##
|
9
|
+
## 1.1.0 - 2017-06-02
|
10
|
+
|
11
|
+
* [FEATURE] Add `FsEmployee#create`
|
12
|
+
|
13
|
+
## 1.0.0 - 2017-06-02
|
10
14
|
|
11
15
|
* [FEATURE] Add `TalentAccount#create`
|
12
16
|
* [FEATURE] Add `TalentAccount#update`
|
data/README.md
CHANGED
@@ -69,6 +69,14 @@ talent_account = HubbleObservatory::TalentAccount.new id: '123456'
|
|
69
69
|
talent_account.update email: 'newuser@example.com'
|
70
70
|
# => '123456'
|
71
71
|
```
|
72
|
+
### FsEmployee#create
|
73
|
+
|
74
|
+
Obtain the token of a employee given the appropriate access token:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
HubbleObservatory::FsEmployee.create access_token: 'ya.29defg'
|
78
|
+
# => 'hb.484562'
|
79
|
+
```
|
72
80
|
|
73
81
|
## How to develop and contribute
|
74
82
|
|
data/hubble_observatory.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'hubble_observatory/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "hubble_observatory"
|
8
8
|
spec.version = HubbleObservatory::VERSION
|
9
|
-
spec.authors = ["Bruce Park"]
|
10
|
-
spec.email = ["bruce.park@fullscreen.net"]
|
9
|
+
spec.authors = ["Bruce Park", "Claudio Baccigalupo"]
|
10
|
+
spec.email = ["bruce.park@fullscreen.net", "claudio@fullscreen.net"]
|
11
11
|
|
12
12
|
spec.summary = %q{A client gem for the Hubble API}
|
13
13
|
spec.description = %q{A client gem for the Hubble API}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module HubbleObservatory
|
2
|
+
# Provides methods to interact with the Hubble API fs-employees endpoint
|
3
|
+
# @see https://hubble.fullscreen.net/api/docs#fsemployees-getting-jwt-token
|
4
|
+
class FsEmployee
|
5
|
+
# @return [String] the token associated with the employee
|
6
|
+
def self.create(access_token:)
|
7
|
+
request = HubbleObservatory::Request.new(attrs: {request_type: :get, route: "fs-employees/jwt-token", query_params: { access_token: access_token}, include_auth_header: false} )
|
8
|
+
response= request.run_request
|
9
|
+
if response && response[:data]
|
10
|
+
response[:data][:attributes][:jwt_token]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -12,16 +12,17 @@ module HubbleObservatory
|
|
12
12
|
def initialize(attrs: {})
|
13
13
|
@request_type = attrs.fetch :request_type, :get
|
14
14
|
@route = attrs.fetch :route, "talent-accounts"
|
15
|
+
@query_params = attrs.fetch :query_params, {}
|
15
16
|
@body_attrs = attrs.fetch :body_attrs, nil
|
16
|
-
@
|
17
|
+
@request_format = attrs.fetch :request_format, :json
|
18
|
+
@auth_header = attrs.fetch :auth_header, false
|
17
19
|
end
|
18
20
|
|
19
21
|
# Sends the request and returns the response
|
20
22
|
def run_request
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
response_for(assign_headers(request), uri)
|
23
|
+
if response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPUnprocessableEntity)
|
24
|
+
parse(response)
|
25
|
+
end
|
25
26
|
end
|
26
27
|
|
27
28
|
# parse the JSON response body
|
@@ -41,27 +42,48 @@ module HubbleObservatory
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def uri
|
44
|
-
@uri ||= URI::HTTPS.build host: host, path: "/api/v1/#{@route}"
|
45
|
+
@uri ||= URI::HTTPS.build host: host, path: "/api/v1/#{@route}", query: URI.encode_www_form(@query_params)
|
45
46
|
end
|
46
47
|
|
47
|
-
def
|
48
|
+
def response
|
48
49
|
Net::HTTP.start(uri.host, 443, use_ssl: true) do |http|
|
49
|
-
http.request
|
50
|
+
http.request create_http_request
|
50
51
|
end
|
51
52
|
rescue *ConnectionError.errors => e
|
52
53
|
raise ConnectionError, e.message
|
53
54
|
end
|
54
55
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
56
|
+
def create_http_request
|
57
|
+
net_http_class = Object.const_get("Net::HTTP::#{@request_type.capitalize}")
|
58
|
+
@http_request ||= net_http_class.new(uri.request_uri).tap do |request|
|
59
|
+
assign_request_body request
|
60
|
+
assign_request_headers request
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def assign_request_body(request)
|
65
|
+
if @body_attrs
|
66
|
+
request.body = serialize_attributes(attributes: @body_attrs).to_json
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def assign_request_headers(request)
|
71
|
+
http_headers = default_headers
|
72
|
+
if @auth_header
|
73
|
+
http_headers.merge!(authorization_header)
|
74
|
+
end
|
75
|
+
http_headers.each_key do |header|
|
76
|
+
request[header] = http_headers[header]
|
58
77
|
end
|
59
78
|
request
|
60
79
|
end
|
61
80
|
|
62
|
-
def
|
63
|
-
{"
|
64
|
-
|
81
|
+
def default_headers
|
82
|
+
{"Content-Type" => "application/vnd.api+json"}
|
83
|
+
end
|
84
|
+
|
85
|
+
def authorization_header
|
86
|
+
{"Authorization" => "Bearer #{ENV['HUBBLE_APP_TOKEN']}"}
|
65
87
|
end
|
66
88
|
|
67
89
|
def host
|
@@ -9,24 +9,24 @@ module HubbleObservatory
|
|
9
9
|
|
10
10
|
# @return [String] the hubble uuid associated with the email
|
11
11
|
def self.create(email:)
|
12
|
-
request = HubbleObservatory::Request.new(attrs: {body_attrs: {email: email}, request_type: :post})
|
13
|
-
@response= request.run_request
|
14
|
-
|
15
|
-
process_account_data(data)
|
12
|
+
request = HubbleObservatory::Request.new(attrs: {body_attrs: {email: email}, request_type: :post, auth_header: true})
|
13
|
+
@response = request.run_request
|
14
|
+
process_account_data(@response)
|
16
15
|
end
|
17
16
|
|
18
17
|
# @return [String] the hubble uuid associated with the email
|
19
18
|
def update(email:)
|
20
|
-
request = HubbleObservatory::Request.new(attrs: {body_attrs: {email: email}, route: "talent-accounts/#{@hubble_uuid}", request_type: :put})
|
19
|
+
request = HubbleObservatory::Request.new(attrs: {body_attrs: {email: email}, route: "talent-accounts/#{@hubble_uuid}", request_type: :put, auth_header: true})
|
21
20
|
@response = request.run_request
|
22
|
-
|
23
|
-
self.class.process_account_data(data)
|
21
|
+
self.class.process_account_data(@response)
|
24
22
|
end
|
25
23
|
|
26
24
|
private
|
27
25
|
|
28
26
|
def self.process_account_data(account_data)
|
29
|
-
|
27
|
+
if account_data
|
28
|
+
extract_attribute_from_data(data: account_data, attribute: :id) || extract_uuid_from_errors(data: account_data)
|
29
|
+
end
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.extract_attribute_from_data(data:, attribute:)
|
data/lib/hubble_observatory.rb
CHANGED
metadata
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubble_observatory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruce Park
|
8
|
+
- Claudio Baccigalupo
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
@@ -97,6 +98,7 @@ dependencies:
|
|
97
98
|
description: A client gem for the Hubble API
|
98
99
|
email:
|
99
100
|
- bruce.park@fullscreen.net
|
101
|
+
- claudio@fullscreen.net
|
100
102
|
executables: []
|
101
103
|
extensions: []
|
102
104
|
extra_rdoc_files: []
|
@@ -115,6 +117,7 @@ files:
|
|
115
117
|
- hubble_observatory.gemspec
|
116
118
|
- lib/hubble_observatory.rb
|
117
119
|
- lib/hubble_observatory/errors.rb
|
120
|
+
- lib/hubble_observatory/fs_employee.rb
|
118
121
|
- lib/hubble_observatory/request.rb
|
119
122
|
- lib/hubble_observatory/talent_account.rb
|
120
123
|
- lib/hubble_observatory/version.rb
|