luma 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/CODE_OF_CONDUCT.md +73 -0
- data/Gemfile +3 -0
- data/README.md +36 -0
- data/Rakefile +10 -0
- data/lib/luma.rb +64 -0
- data/lib/luma/authentication.rb +77 -0
- data/lib/luma/connection.rb +28 -0
- data/lib/luma/luma_exception.rb +22 -0
- data/lib/luma/version.rb +3 -0
- data/luma.gemspec +39 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 90cb5a8a4e2004979fffe11787e075eadd846e0212772982ca8ecaf14c0dfa4b
|
4
|
+
data.tar.gz: 0f984cb029cf220619d3e30410a352d24a8b56dfe7df1dc02fe6bec7f762d82d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1323627f934c929039a9c00d4f006177fb8f90d76f1379889a339c57948f247d5f0dc23043c174513adb3a312fe6213059db03bbb8432c9e34389e6e70c1d74d
|
7
|
+
data.tar.gz: 47853cccd286d61f368688cd8553b3fc6128b3b905a92791e63589174e92a09b82dc17282e63bc0a882bc8cc416b832753bfd7d2c919cfc4f44ef53b01962ec6
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
education, socio-economic status, nationality, personal appearance, race,
|
10
|
+
religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
72
|
+
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# luma
|
2
|
+
Ruby gem for Luma Health API
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'luma'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install luma
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Configuration
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
Luma.configure do |c|
|
26
|
+
c.email = ENV['LUMA_EMAIL']
|
27
|
+
c.password = ENV['LUMA_PASSWORD']
|
28
|
+
c.api_endpoint = 'http://hello.com' # Defaults to Luma endpoint
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
data/Rakefile
ADDED
data/lib/luma.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'hashie'
|
3
|
+
require 'luma/version'
|
4
|
+
require 'luma/luma_exception'
|
5
|
+
require 'luma/connection'
|
6
|
+
require 'luma/authentication'
|
7
|
+
|
8
|
+
module Luma
|
9
|
+
class Configuration
|
10
|
+
attr_accessor :email, :password
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@email = nil
|
14
|
+
@password = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def api_endpoint=(endpoint)
|
18
|
+
Connection.base_uri(endpoint.freeze)
|
19
|
+
end
|
20
|
+
|
21
|
+
def api_endpoint
|
22
|
+
return Connection.base_uri
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_h
|
26
|
+
return {
|
27
|
+
email: @email,
|
28
|
+
password: @password,
|
29
|
+
api_endpoint: api_endpoint
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def from_h(h)
|
34
|
+
self.email = h[:email]
|
35
|
+
self.password = h[:password]
|
36
|
+
self.api_endpoint = h[:api_endpoint]
|
37
|
+
|
38
|
+
return self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class << self
|
43
|
+
def configuration
|
44
|
+
@configuration ||= Configuration.new
|
45
|
+
end
|
46
|
+
|
47
|
+
def configure
|
48
|
+
yield(configuration)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Luma API client
|
53
|
+
class LumaClient
|
54
|
+
class << self
|
55
|
+
def connection
|
56
|
+
@connection ||= Connection.new
|
57
|
+
end
|
58
|
+
|
59
|
+
def release
|
60
|
+
@connection = nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Luma
|
2
|
+
class Authentication < Connection
|
3
|
+
attr_accessor :response, :validation_response
|
4
|
+
|
5
|
+
BASE_ENDPOINT = '/api'.freeze
|
6
|
+
AUTH_ENDPOINT = "#{BASE_ENDPOINT}/users/login".freeze
|
7
|
+
VALIDATE_ENDPOINT = "#{BASE_ENDPOINT}/tokens/validate".freeze
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@response = nil
|
11
|
+
@validation_response = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def authenticate
|
15
|
+
if (self.expires?)
|
16
|
+
request = {
|
17
|
+
body: { email: Luma.configuration.email, password: Luma.configuration.password },
|
18
|
+
endpoint: AUTH_ENDPOINT
|
19
|
+
}
|
20
|
+
|
21
|
+
response = self.request(**request, auth: false)
|
22
|
+
|
23
|
+
if (false == response.ok?)
|
24
|
+
@response = nil
|
25
|
+
raise LumaException.from_response(response, msg: 'Authentication')
|
26
|
+
else
|
27
|
+
@response = response
|
28
|
+
validate
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
return self
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate
|
36
|
+
request = {
|
37
|
+
body: { token: access_token },
|
38
|
+
endpoint: VALIDATE_ENDPOINT
|
39
|
+
}
|
40
|
+
|
41
|
+
response = self.request(**request, auth: false)
|
42
|
+
|
43
|
+
if (false == response.ok?)
|
44
|
+
@response = nil
|
45
|
+
raise LumaException.from_response(response, msg: 'Authentication Validation')
|
46
|
+
else
|
47
|
+
@validation_response = response
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def access_token
|
52
|
+
return @response['token'] if @response
|
53
|
+
end
|
54
|
+
|
55
|
+
def expiry
|
56
|
+
return @validation_response['exp'] if @validation_response
|
57
|
+
end
|
58
|
+
|
59
|
+
def expires?
|
60
|
+
if (self.expiry)
|
61
|
+
return self.expiry <= (Time.now.to_f * 1000).floor
|
62
|
+
else
|
63
|
+
return true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def access_header
|
68
|
+
return {
|
69
|
+
'X-Access-Token' => self.access_token,
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def expire!
|
74
|
+
@response = nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Luma
|
2
|
+
class Connection
|
3
|
+
DEFAULT_ENDPOINT = '/endpoint'.freeze
|
4
|
+
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
base_uri 'https://api.lumahealth.io/'.freeze
|
8
|
+
|
9
|
+
headers 'Content-Type' => 'application/json'
|
10
|
+
|
11
|
+
format :json
|
12
|
+
|
13
|
+
def request(endpoint: DEFAULT_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post)
|
14
|
+
body = body.to_json if body.is_a?(Hash)
|
15
|
+
headers = auth_header.merge(headers) if auth
|
16
|
+
|
17
|
+
self.class.send("#{verb}", endpoint, body: body, headers: headers)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def auth_header
|
23
|
+
@auth ||= Authentication.new
|
24
|
+
|
25
|
+
return @auth.authenticate.access_header
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Luma
|
2
|
+
class LumaException < Exception
|
3
|
+
def self.from_response(response, msg: nil)
|
4
|
+
exception_msg = "Failed #{msg}:"
|
5
|
+
exception_msg << " HTTP code: #{response.code} MSG: "
|
6
|
+
|
7
|
+
begin
|
8
|
+
error_response = JSON.parse(response.body)
|
9
|
+
|
10
|
+
if (error_response.is_a?(Hash) && error_response.include?("Meta") && error_response["Meta"].include?("Errors"))
|
11
|
+
exception_msg << error_response["Meta"]["Errors"]
|
12
|
+
else
|
13
|
+
exception_msg << error_response
|
14
|
+
end
|
15
|
+
rescue JSON::ParserError
|
16
|
+
exception_msg << response.body
|
17
|
+
end
|
18
|
+
|
19
|
+
return LumaException.new(exception_msg)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/luma/version.rb
ADDED
data/luma.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'luma/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'luma'
|
7
|
+
spec.version = Luma::VERSION
|
8
|
+
spec.authors = ['Angela Rodriguez']
|
9
|
+
spec.email = ['angela.rodriguez@weinfuse.com']
|
10
|
+
|
11
|
+
spec.summary = 'Ruby wrapper for the Luma Health API'
|
12
|
+
spec.homepage = 'https://github.com/WeInfuse/luma'
|
13
|
+
|
14
|
+
# Prevent pushing this gem to RubyGems.org.
|
15
|
+
if spec.respond_to?(:metadata)
|
16
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
17
|
+
else
|
18
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
19
|
+
'public gem pushes.'
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
f.match?(%r{^(test|spec|features|bin|helpers|)/}) || f.match?(%r{^(\.[[:alnum:]]+)})
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
spec.licenses = ['MIT']
|
30
|
+
|
31
|
+
spec.add_dependency 'httparty', '~> 0.18'
|
32
|
+
spec.add_dependency 'hashie', '~> 3.5'
|
33
|
+
spec.add_development_dependency 'bundler', '>=1', '<3'
|
34
|
+
spec.add_development_dependency 'byebug', '~> 11'
|
35
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
36
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
37
|
+
spec.add_development_dependency 'webmock', '~> 3.1'
|
38
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: luma
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Angela Rodriguez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-06-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.18'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.18'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hashie
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.5'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '3'
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: byebug
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '11'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '11'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: minitest
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '5.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '5.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rake
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '10.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '10.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: webmock
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '3.1'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '3.1'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: yard
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0.9'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0.9'
|
131
|
+
description:
|
132
|
+
email:
|
133
|
+
- angela.rodriguez@weinfuse.com
|
134
|
+
executables: []
|
135
|
+
extensions: []
|
136
|
+
extra_rdoc_files: []
|
137
|
+
files:
|
138
|
+
- CHANGELOG.md
|
139
|
+
- CODE_OF_CONDUCT.md
|
140
|
+
- Gemfile
|
141
|
+
- README.md
|
142
|
+
- Rakefile
|
143
|
+
- lib/luma.rb
|
144
|
+
- lib/luma/authentication.rb
|
145
|
+
- lib/luma/connection.rb
|
146
|
+
- lib/luma/luma_exception.rb
|
147
|
+
- lib/luma/version.rb
|
148
|
+
- luma.gemspec
|
149
|
+
homepage: https://github.com/WeInfuse/luma
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
metadata:
|
153
|
+
allowed_push_host: https://rubygems.org
|
154
|
+
post_install_message:
|
155
|
+
rdoc_options: []
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
requirements: []
|
169
|
+
rubygems_version: 3.1.4
|
170
|
+
signing_key:
|
171
|
+
specification_version: 4
|
172
|
+
summary: Ruby wrapper for the Luma Health API
|
173
|
+
test_files: []
|