hubble_observatory 1.0.0.alpha → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/hubble_observatory/request.rb +72 -0
- data/lib/hubble_observatory/talent_account.rb +6 -50
- data/lib/hubble_observatory/version.rb +1 -1
- data/lib/hubble_observatory.rb +1 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27650ed552aa23d7948ec0ffc6d28252bf691d9c
|
4
|
+
data.tar.gz: af1c410a1aad8a0c7251028bfa7d4de083321c21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d3af169ab0f4e11347538f9bda08abc04141365532bf6b81ff2f5148e82f7c488b6beccb54a11ebbb56d9c9c0ca2b132b6453feeedf3d46250499e6959f989a
|
7
|
+
data.tar.gz: cbb848f023f738c390240af16159aaea02d5a91b8ecbe4181ad0070c6d3704251e0e370f34f7bac85408a36e1ce8afbd3bac9e93a24c9af382e826b9b04c04a6
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
For more information about changelogs, check
|
6
|
+
[Keep a Changelog](http://keepachangelog.com) and
|
7
|
+
[Vandamme](http://tech-angels.github.io/vandamme).
|
8
|
+
|
9
|
+
## 0.1.0 - 2017-06-02
|
10
|
+
|
11
|
+
* [FEATURE] Add `TalentAccount#create`
|
12
|
+
* [FEATURE] Add `TalentAccount#update`
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module HubbleObservatory
|
2
|
+
# A wrapper around +Net::HTTP+ to send HTTP requests to the Hubble API and
|
3
|
+
# return their result or raise an error if the result is unexpected.
|
4
|
+
# The basic way to use Request is by calling +run_request+ on an instance.
|
5
|
+
class Request
|
6
|
+
# Initializes a Request object.
|
7
|
+
# @param [Hash] attrs are the options for the request.
|
8
|
+
# @option attrs [Symbol] :method (:get) The HTTP method to use.
|
9
|
+
# @option attrs [String] :route The (base) route of the API endpoint
|
10
|
+
# @option attrs [Hash] :body_attrs ({}) The attributes for the body
|
11
|
+
# per the JSON API spec
|
12
|
+
def initialize(attrs: {})
|
13
|
+
@request_type = attrs.fetch :request_type, :get
|
14
|
+
@route = attrs.fetch :route, "talent-accounts"
|
15
|
+
@body_attrs = attrs.fetch :body_attrs, nil
|
16
|
+
@error_message = attrs.fetch :error_message, ->(body) {"Error: #{body}"}
|
17
|
+
end
|
18
|
+
|
19
|
+
# Sends the request and returns the response
|
20
|
+
def run_request
|
21
|
+
net_http_class = Object.const_get("Net::HTTP::#{@request_type.capitalize}")
|
22
|
+
request = net_http_class.new uri
|
23
|
+
request.body = serialize_attributes(attributes: @body_attrs).to_json
|
24
|
+
response_for(assign_headers(request), uri)
|
25
|
+
end
|
26
|
+
|
27
|
+
# parse the JSON response body
|
28
|
+
def parse(response)
|
29
|
+
JSON.parse response.body, symbolize_names: true
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def serialize_attributes(attributes:)
|
35
|
+
{
|
36
|
+
data: {
|
37
|
+
type: @route,
|
38
|
+
attributes: attributes
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def uri
|
44
|
+
@uri ||= URI::HTTPS.build host: host, path: "/api/v1/#{@route}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def response_for(http_request, uri)
|
48
|
+
Net::HTTP.start(uri.host, 443, use_ssl: true) do |http|
|
49
|
+
http.request http_request
|
50
|
+
end
|
51
|
+
rescue *ConnectionError.errors => e
|
52
|
+
raise ConnectionError, e.message
|
53
|
+
end
|
54
|
+
|
55
|
+
def assign_headers(request)
|
56
|
+
headers.each_key do |header|
|
57
|
+
request[header] = headers[header]
|
58
|
+
end
|
59
|
+
request
|
60
|
+
end
|
61
|
+
|
62
|
+
def headers
|
63
|
+
{"Authorization" => "Bearer #{ENV['HUBBLE_APP_TOKEN']}",
|
64
|
+
"Content-Type" => "application/vnd.api+json"}
|
65
|
+
end
|
66
|
+
|
67
|
+
def host
|
68
|
+
subdomain = ENV['HUBBLE_ENV'] == 'production' ? 'hubble' : 'rc-hubble'
|
69
|
+
"#{subdomain}.fullscreen.net"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -9,31 +9,22 @@ module HubbleObservatory
|
|
9
9
|
|
10
10
|
# @return [String] the hubble uuid associated with the email
|
11
11
|
def self.create(email:)
|
12
|
-
|
12
|
+
request = HubbleObservatory::Request.new(attrs: {body_attrs: {email: email}, request_type: :post})
|
13
|
+
@response= request.run_request
|
14
|
+
data = request.parse(@response)
|
13
15
|
process_account_data(data)
|
14
16
|
end
|
15
17
|
|
16
18
|
# @return [String] the hubble uuid associated with the email
|
17
19
|
def update(email:)
|
18
|
-
|
20
|
+
request = HubbleObservatory::Request.new(attrs: {body_attrs: {email: email}, route: "talent-accounts/#{@hubble_uuid}", request_type: :put})
|
21
|
+
@response = request.run_request
|
22
|
+
data = request.parse(@response)
|
19
23
|
self.class.process_account_data(data)
|
20
24
|
end
|
21
25
|
|
22
26
|
private
|
23
27
|
|
24
|
-
def self.serialize_attributes(attributes:)
|
25
|
-
{
|
26
|
-
data: {
|
27
|
-
type: "talent-accounts",
|
28
|
-
attributes: attributes
|
29
|
-
}
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.parse(response)
|
34
|
-
data_response = JSON.parse response.body, symbolize_names: true
|
35
|
-
end
|
36
|
-
|
37
28
|
def self.process_account_data(account_data)
|
38
29
|
extract_attribute_from_data(data: account_data, attribute: :id) || extract_uuid_from_errors(data: account_data)
|
39
30
|
end
|
@@ -45,40 +36,5 @@ module HubbleObservatory
|
|
45
36
|
def self.extract_uuid_from_errors(data:)
|
46
37
|
data.fetch(:errors, [{}])[0].fetch(:hubble_uuid, nil)
|
47
38
|
end
|
48
|
-
|
49
|
-
def self.process_request(route:, body_attrs:, request_type:)
|
50
|
-
uri = URI::HTTPS.build host: host,
|
51
|
-
path: "/api/v1/#{route}"
|
52
|
-
net_http_class = Object.const_get("Net::HTTP::#{request_type.capitalize}")
|
53
|
-
body = serialize_attributes(attributes: body_attrs)
|
54
|
-
request = net_http_class.new uri
|
55
|
-
request.body = body.to_json
|
56
|
-
response_for(assign_headers(request), uri)
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.response_for(http_request, uri)
|
60
|
-
Net::HTTP.start(uri.host, 443, use_ssl: true) do |http|
|
61
|
-
http.request http_request
|
62
|
-
end
|
63
|
-
rescue *ConnectionError.errors => e
|
64
|
-
raise ConnectionError, e.message
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.assign_headers(request)
|
68
|
-
headers.each_key do |header|
|
69
|
-
request[header] = headers[header]
|
70
|
-
end
|
71
|
-
request
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.host
|
75
|
-
subdomain = ENV['HUBBLE_ENV'] == 'production' ? 'hubble' : 'rc-hubble'
|
76
|
-
"#{subdomain}.fullscreen.net"
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.headers
|
80
|
-
{"Authorization" => "Bearer #{ENV['HUBBLE_APP_TOKEN']}",
|
81
|
-
"Content-Type" => "application/vnd.api+json"}
|
82
|
-
end
|
83
39
|
end
|
84
40
|
end
|
data/lib/hubble_observatory.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubble_observatory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruce Park
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- ".gitignore"
|
106
106
|
- ".rspec"
|
107
107
|
- ".travis.yml"
|
108
|
+
- CHANGELOG.md
|
108
109
|
- Gemfile
|
109
110
|
- LICENSE.txt
|
110
111
|
- README.md
|
@@ -114,6 +115,7 @@ files:
|
|
114
115
|
- hubble_observatory.gemspec
|
115
116
|
- lib/hubble_observatory.rb
|
116
117
|
- lib/hubble_observatory/errors.rb
|
118
|
+
- lib/hubble_observatory/request.rb
|
117
119
|
- lib/hubble_observatory/talent_account.rb
|
118
120
|
- lib/hubble_observatory/version.rb
|
119
121
|
homepage: https://github.com/Fullscreen/hubble_observatory
|
@@ -131,9 +133,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
133
|
version: 2.1.2
|
132
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
135
|
requirements:
|
134
|
-
- - "
|
136
|
+
- - ">="
|
135
137
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
138
|
+
version: '0'
|
137
139
|
requirements: []
|
138
140
|
rubyforge_project:
|
139
141
|
rubygems_version: 2.6.11
|