hubble_observatory 1.0.0.alpha
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 +7 -0
- data/.env.example +2 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/hubble_observatory.gemspec +32 -0
- data/lib/hubble_observatory.rb +5 -0
- data/lib/hubble_observatory/errors.rb +18 -0
- data/lib/hubble_observatory/talent_account.rb +84 -0
- data/lib/hubble_observatory/version.rb +4 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4a1f79fe1250bd92727ec3c05039b0de394b5a8d
|
4
|
+
data.tar.gz: 0b100bb0b20e83bf09d8152c1be1d8d34d0acafe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d51fdd664d111a922c1f63e3743a2589ccf678cd4a78427f85f1d131cee6660f87d2a28b0d35f4bdc87df820e24fb84336097610a1760f67b973749ccc8a181
|
7
|
+
data.tar.gz: 7cc8f952d390910f064c2365099a142a80f39507b36d6b8e7c5434eee50709dcdf2543a216e9efbef4a8f26dce4dd8819019e18751342bc9a4a604ee84f9aa9f
|
data/.env.example
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Fullscreen, Inc
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
Hubble Observatory
|
2
|
+
==================
|
3
|
+
|
4
|
+
Hubble Observatory is a Ruby library to interact with the Hubble API.
|
5
|
+
|
6
|
+
The **source code** is available on [GitHub](https://github.com/fullscreen/hubble_observatory) and the **documentation** on [RubyDoc](http://www.rubydoc.info/gems/hubble_observatory/frames).
|
7
|
+
|
8
|
+
[](https://travis-ci.org/Fullscreen/hubble_observatory)
|
9
|
+
[](https://coveralls.io/r/Fullscreen/hubble_observatory)
|
10
|
+
[](https://gemnasium.com/Fullscreen/hubble_observatory)
|
11
|
+
[](https://codeclimate.com/github/Fullscreen/hubble_observatory)
|
12
|
+
[](http://www.rubydoc.info/gems/hubble_observatory/frames)
|
13
|
+
[](http://rubygems.org/gems/hubble_observatory)
|
14
|
+
|
15
|
+
After [registering your app](https://fullscreen.github.io/hubble_observatory/), you can run commands like:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
HubbleObservatory::TalentAccount.create email: 'user@example.com'
|
19
|
+
# => '123456'
|
20
|
+
```
|
21
|
+
|
22
|
+
The **full documentation** is available at [rubydoc.info](http://www.rubydoc.info/gems/hubble_observatory/frames).
|
23
|
+
|
24
|
+
|
25
|
+
## Installation and Configuration
|
26
|
+
|
27
|
+
Add this line to your application’s Gemfile:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gem 'hubble_observatory'
|
31
|
+
```
|
32
|
+
|
33
|
+
And then execute:
|
34
|
+
|
35
|
+
$ bundle
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
|
39
|
+
$ gem install hubble_observatory
|
40
|
+
|
41
|
+
Set the following ENV variables in your Ruby/Rails application
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
ENV['HUBBLE_APP_TOKEN'] = "<app token to access Hubble API>"
|
45
|
+
ENV['HUBBLE_ENV'] = "production"
|
46
|
+
```
|
47
|
+
|
48
|
+
If you don’t set `ENV['HUBBLE_ENV']` to "production", the staging Hubble API will be targeted.
|
49
|
+
|
50
|
+
## How to use
|
51
|
+
|
52
|
+
Hubble Observatory provide only two methods to create and update talent accounts.
|
53
|
+
|
54
|
+
### TalentAccount.create
|
55
|
+
|
56
|
+
Obtain the ID of Talent Account given the corresponding email:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
talent_account = HubbleObservatory::TalentAccount.create email: 'user@example.com'
|
60
|
+
# => '123456'
|
61
|
+
```
|
62
|
+
|
63
|
+
### TalentAccount#update
|
64
|
+
|
65
|
+
Update the email of a Talent Account give the corresponding ID:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
talent_account = HubbleObservatory::TalentAccount.new id: '123456'
|
69
|
+
talent_account.update email: 'newuser@example.com'
|
70
|
+
# => '123456'
|
71
|
+
```
|
72
|
+
|
73
|
+
## How to develop and contribute
|
74
|
+
|
75
|
+
To install the app and its dependencies, run `bin/setup`.
|
76
|
+
|
77
|
+
To execute the test suite, run:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
HUBBLE_APP_TOKEN=<token> bundle exec rake
|
81
|
+
```
|
82
|
+
|
83
|
+
To release a new version, run: `bundle exec rake release`.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hubble_api_client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hubble_observatory/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hubble_observatory"
|
8
|
+
spec.version = HubbleObservatory::VERSION
|
9
|
+
spec.authors = ["Bruce Park"]
|
10
|
+
spec.email = ["bruce.park@fullscreen.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{A client gem for the Hubble API}
|
13
|
+
spec.description = %q{A client gem for the Hubble API}
|
14
|
+
spec.homepage = "https://github.com/Fullscreen/hubble_observatory"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.required_ruby_version = '>= 2.1.2'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
28
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
29
|
+
spec.add_development_dependency 'coveralls', '~> 0.8.21'
|
30
|
+
spec.add_development_dependency 'pry-nav', '~> 0.2.4'
|
31
|
+
spec.add_development_dependency 'yard', '~> 0.9.9'
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# An object-oriented client for the Hubble API
|
2
|
+
module HubbleObservatory
|
3
|
+
# Documents the connection errors that can occur
|
4
|
+
class ConnectionError < StandardError
|
5
|
+
# Possible list of connection errors that can occur
|
6
|
+
def self.errors
|
7
|
+
[
|
8
|
+
OpenSSL::SSL::SSLError,
|
9
|
+
Errno::ETIMEDOUT,
|
10
|
+
Errno::EHOSTUNREACH,
|
11
|
+
Errno::ENETUNREACH,
|
12
|
+
Errno::ECONNRESET,
|
13
|
+
Net::OpenTimeout,
|
14
|
+
SocketError
|
15
|
+
]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module HubbleObservatory
|
2
|
+
# Provides methods to interact with the Hubble API talent-accounts endpoint
|
3
|
+
# @see https://hubble.fullscreen.net/api/docs#talentaccounts-create-talent-account
|
4
|
+
class TalentAccount
|
5
|
+
|
6
|
+
def initialize(id:)
|
7
|
+
@hubble_uuid = id
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [String] the hubble uuid associated with the email
|
11
|
+
def self.create(email:)
|
12
|
+
data = parse process_request(route: "talent-accounts", body_attrs: {email: email}, request_type: "post")
|
13
|
+
process_account_data(data)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [String] the hubble uuid associated with the email
|
17
|
+
def update(email:)
|
18
|
+
data = self.class.parse self.class.process_request(route: "talent-accounts/#{@hubble_uuid}", body_attrs: {email: email}, request_type: "put")
|
19
|
+
self.class.process_account_data(data)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
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
|
+
def self.process_account_data(account_data)
|
38
|
+
extract_attribute_from_data(data: account_data, attribute: :id) || extract_uuid_from_errors(data: account_data)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.extract_attribute_from_data(data:, attribute:)
|
42
|
+
data.fetch(:data, {}).fetch(attribute, nil)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.extract_uuid_from_errors(data:)
|
46
|
+
data.fetch(:errors, [{}])[0].fetch(:hubble_uuid, nil)
|
47
|
+
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
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hubble_observatory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bruce Park
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.21
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.21
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-nav
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.2.4
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.2.4
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.9.9
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.9.9
|
97
|
+
description: A client gem for the Hubble API
|
98
|
+
email:
|
99
|
+
- bruce.park@fullscreen.net
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".env.example"
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- hubble_observatory.gemspec
|
115
|
+
- lib/hubble_observatory.rb
|
116
|
+
- lib/hubble_observatory/errors.rb
|
117
|
+
- lib/hubble_observatory/talent_account.rb
|
118
|
+
- lib/hubble_observatory/version.rb
|
119
|
+
homepage: https://github.com/Fullscreen/hubble_observatory
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.1.2
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 1.3.1
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.6.11
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: A client gem for the Hubble API
|
143
|
+
test_files: []
|