v2_intuity 1.0.0 → 1.0.1
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/Rakefile +3 -3
- data/bin/console +3 -3
- data/lib/requirements.rb +16 -12
- data/lib/v2_intuity/clients/client.rb +114 -0
- data/lib/v2_intuity/clients/rest_api.rb +15 -0
- data/lib/v2_intuity/clients/stream_api.rb +12 -0
- data/lib/v2_intuity/endpoints/endpoint.rb +4 -0
- data/lib/v2_intuity/endpoints/stream.rb +7 -1
- data/lib/v2_intuity/endpoints/user.rb +1 -0
- data/lib/v2_intuity/query_filters/access_token.rb +10 -0
- data/lib/v2_intuity/{filters → query_filters}/asc_created_at.rb +2 -2
- data/lib/v2_intuity/{filters → query_filters}/asc_updated_at.rb +2 -2
- data/lib/v2_intuity/{filters → query_filters}/date.rb +2 -2
- data/lib/v2_intuity/{filters → query_filters}/dec_created_at.rb +2 -2
- data/lib/v2_intuity/{filters → query_filters}/dec_updated_at.rb +2 -2
- data/lib/v2_intuity/{filters → query_filters}/end_date.rb +2 -2
- data/lib/v2_intuity/query_filters/filter.rb +22 -0
- data/lib/v2_intuity/query_filters/format_redirect.rb +10 -0
- data/lib/v2_intuity/{filters → query_filters}/sort.rb +3 -3
- data/lib/v2_intuity/query_filters/source.rb +10 -0
- data/lib/v2_intuity/{filters → query_filters}/start_date.rb +2 -2
- data/lib/v2_intuity/resource_filters/measurement.rb +9 -0
- data/lib/v2_intuity/resource_filters/nutrition.rb +9 -0
- data/lib/v2_intuity/resource_filters/resource_filter.rb +19 -0
- data/lib/v2_intuity/resource_filters/sleep.rb +9 -0
- data/lib/v2_intuity/resource_filters/summary.rb +9 -0
- data/lib/v2_intuity/resource_filters/workout.rb +9 -0
- data/lib/v2_intuity/streams/stream.rb +36 -9
- data/lib/v2_intuity/users/user.rb +29 -26
- data/lib/v2_intuity/version.rb +1 -1
- data/lib/v2_intuity.rb +11 -7
- data/v2_intuity.gemspec +12 -13
- metadata +22 -15
- data/lib/v2_intuity/client.rb +0 -118
- data/lib/v2_intuity/filters/access_token.rb +0 -10
- data/lib/v2_intuity/filters/filter.rb +0 -22
- data/lib/v2_intuity/filters/format_redirect.rb +0 -10
- data/lib/v2_intuity/filters/resource_filters.rb +0 -20
- data/lib/v2_intuity/filters/source.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0d724b6101183d0b427d9d0dfd8d2bf28bf6301
|
4
|
+
data.tar.gz: 5cb7ee9ae865c8e62e7a39b70a65d042c371be8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75561a970b89a7afa5e046570086a8a539451b4019c5adc07505d0b1574142c650f7c7949bfdcd3dea796c4ea65a5d3f886aea16edb40662cfc486af4a1c93c9
|
7
|
+
data.tar.gz: cf798fe739a306d91cfe4ffafda82e13fd3afddcf4d4134b4ebac74569c4ef962fe88f44ead865e7d5ca3efb1bdd1ddc6f758dbda2f72f8aad4a2112eb0fd9d2
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'v2_intuity'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "v2_intuity"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/lib/requirements.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
1
|
+
require 'v2_intuity/clients/client'
|
2
|
+
require 'v2_intuity/request_error'
|
3
|
+
require 'v2_intuity/response'
|
4
|
+
require 'v2_intuity/request'
|
5
|
+
require 'v2_intuity/version'
|
6
|
+
require 'v2_intuity/query_filters/filter'
|
7
|
+
require 'v2_intuity/endpoints/endpoint'
|
8
|
+
require 'v2_intuity/query_filters/sort'
|
9
|
+
require 'v2_intuity/query_filters/date'
|
10
|
+
require 'v2_intuity/headers/header'
|
11
|
+
require 'v2_intuity/resource_filters/resource_filter'
|
11
12
|
|
12
13
|
ROOT = File.dirname(File.expand_path(File.dirname(__FILE__))).freeze
|
13
14
|
|
14
|
-
Dir["#{ROOT}/lib/v2_intuity/
|
15
|
-
Dir["#{ROOT}/lib/v2_intuity/
|
15
|
+
Dir["#{ROOT}/lib/v2_intuity/clients/*.rb"].each { |file| require file unless file =~ /client.rb/ }
|
16
|
+
Dir["#{ROOT}/lib/v2_intuity/endpoints/*.rb"].each { |file| require file unless file =~ /endpoint.rb/ }
|
17
|
+
Dir["#{ROOT}/lib/v2_intuity/query_filters/*.rb"].each { |file| require file unless file =~ /query_filter.rb|sort.rb|date.rb/ }
|
16
18
|
Dir["#{ROOT}/lib/v2_intuity/headers/*.rb"].each { |file| require file unless file =~ /header.rb/ }
|
19
|
+
Dir["#{ROOT}/lib/v2_intuity/streams/*.rb"].each { |file| require file }
|
20
|
+
Dir["#{ROOT}/lib/v2_intuity/resource_filters/*.rb"].each { |file| require file unless file =~ /resource_filter.rb/ }
|
17
21
|
Dir["#{ROOT}/lib/v2_intuity/users/*.rb"].each { |file| require file }
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
module V2Intuity
|
3
|
+
module Clients
|
4
|
+
class Client
|
5
|
+
attr_accessor :token, :org_id, :accept,
|
6
|
+
:content_type, :base_uri,
|
7
|
+
:httparty_client
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
@token = attributes[:token]
|
11
|
+
raise 'Client requires token' unless @token
|
12
|
+
|
13
|
+
@base_uri = attributes.fetch(:base_uri, nil)
|
14
|
+
@accept = attributes.fetch(:accept, 'application/json')
|
15
|
+
@content_type = attributes.fetch(:content_type, 'application/json')
|
16
|
+
end
|
17
|
+
|
18
|
+
def send_request(request)
|
19
|
+
case request.method
|
20
|
+
when V2Intuity::Request::METHODS[:get], V2Intuity::Request::METHODS[:delete]
|
21
|
+
@httparty_client.send(request.method.to_sym, request.uri, query: request.options[:query_filters], headers: request.options[:headers]) # puts re.request.last_uri.to_s
|
22
|
+
|
23
|
+
when V2Intuity::Request::METHODS[:post], V2Intuity::Request::METHODS[:put]
|
24
|
+
@httparty_client.send(request.method.to_sym, request.uri, query: request.options[:query_filters],
|
25
|
+
body: request.options[:body].to_json,
|
26
|
+
headers: request.options[:headers])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_and_send_request(endpoint, options = {})
|
31
|
+
@request = build_request(endpoint, options)
|
32
|
+
send_request_generate_response(@request)
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_request(endpoint, options = {})
|
36
|
+
http_party_options = {}
|
37
|
+
@query_filters = {}
|
38
|
+
@headers = {}
|
39
|
+
|
40
|
+
method = options[:method].to_s.nil? ? V2Intuity::Request::METHODS[:get] : options[:method]
|
41
|
+
id = options[:id].to_s.nil? ? nil : options[:id]
|
42
|
+
|
43
|
+
query_filters, headers = combine_query_filters_and_headers(options)
|
44
|
+
|
45
|
+
http_party_options[:query_filters] = query_filters
|
46
|
+
http_party_options[:headers] = headers
|
47
|
+
http_party_options[:body] = options[:body] unless method == V2Intuity::Request::METHODS[:get]
|
48
|
+
|
49
|
+
uri = endpoint.uri(org_id: org_id, id: id, base_uri: base_uri)
|
50
|
+
|
51
|
+
V2Intuity::Request.new(method: method, uri: uri, options: http_party_options)
|
52
|
+
end
|
53
|
+
|
54
|
+
def send_request_generate_response(request)
|
55
|
+
response = V2Intuity::Response.new(request: request)
|
56
|
+
|
57
|
+
self.httparty_client ||= HTTParty
|
58
|
+
|
59
|
+
response.define_response_and_json(send_request(request))
|
60
|
+
|
61
|
+
return response if response.response.success?
|
62
|
+
|
63
|
+
error = build_error(response)
|
64
|
+
|
65
|
+
response.add_errors(error)
|
66
|
+
|
67
|
+
response
|
68
|
+
|
69
|
+
rescue StandardError => e
|
70
|
+
response.add_errors(RequestError.new(code: 400, message: e.message))
|
71
|
+
|
72
|
+
response
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def build_error(response)
|
78
|
+
json = response.g_json
|
79
|
+
if json
|
80
|
+
V2Intuity::RequestError.new(code: response.code, message: response.message, description: json['message'])
|
81
|
+
else
|
82
|
+
V2Intuity::RequestError.new(code: response.code, message: response.message)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def default_query_filters
|
87
|
+
[V2Intuity::QueryFilters::AccessToken.new(value: @token)]
|
88
|
+
end
|
89
|
+
|
90
|
+
def default_headers
|
91
|
+
[V2Intuity::Headers::Accept.new(value: @accept), V2Intuity::Headers::ContentType.new(value: @content_type)]
|
92
|
+
end
|
93
|
+
|
94
|
+
def combine_query_filters_and_headers(options)
|
95
|
+
total_query_filters = {}
|
96
|
+
total_headers = {}
|
97
|
+
filter_array = options[:query_filters].is_a?(Array) ? options[:query_filters] : []
|
98
|
+
header_array = options[:headers].is_a?(Array) ? options[:headers] : []
|
99
|
+
|
100
|
+
unique_query_filters = (default_query_filters + filter_array)
|
101
|
+
unique_query_filters.each do |filter|
|
102
|
+
total_query_filters.merge!(filter.to_hash)
|
103
|
+
end
|
104
|
+
|
105
|
+
unique_headers = (default_headers + header_array)
|
106
|
+
unique_headers.each do |header|
|
107
|
+
total_headers.merge!(header.to_hash)
|
108
|
+
end
|
109
|
+
|
110
|
+
[total_query_filters, total_headers]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module V2Intuity
|
2
|
+
module Clients
|
3
|
+
class RestApi < Client
|
4
|
+
def initialize(options = {})
|
5
|
+
super
|
6
|
+
@base_uri = options[:rest_uri]
|
7
|
+
|
8
|
+
raise 'RestApi Client requires rest_uri' unless @base_uri
|
9
|
+
|
10
|
+
@org_id = options[:org_id]
|
11
|
+
raise 'Client requires org_id' unless @org_id
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -25,9 +25,13 @@ module V2Intuity
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def uri_options(options = {})
|
28
|
+
puts "whatt the hell"
|
28
29
|
@base_uri ||= options[:base_uri]
|
29
30
|
@org_id ||= options[:org_id]
|
30
31
|
@id ||= options[:id]
|
32
|
+
|
33
|
+
raise 'org_id is needed' unless @org_id
|
34
|
+
raise 'base_uri is needed' unless @base_uri
|
31
35
|
end
|
32
36
|
|
33
37
|
def sign_with
|
@@ -2,6 +2,9 @@ module V2Intuity
|
|
2
2
|
module Endpoints
|
3
3
|
class Stream < Endpoint
|
4
4
|
def initialize(options = {})
|
5
|
+
super
|
6
|
+
@org_id = nil
|
7
|
+
@path = nil
|
5
8
|
@base_uri = options[:stream_uri]
|
6
9
|
@endpoint = Endpoint::ENDPOINTS[:streams]
|
7
10
|
end
|
@@ -16,8 +19,11 @@ module V2Intuity
|
|
16
19
|
end
|
17
20
|
|
18
21
|
def uri_options(options = {})
|
19
|
-
|
22
|
+
|
23
|
+
@base_uri ||= options[:base_uri]
|
20
24
|
@id ||= options[:id]
|
25
|
+
|
26
|
+
raise 'base_uri is needed' unless @base_uri
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module V2Intuity
|
2
|
+
module QueryFilters
|
3
|
+
class QueryFilter
|
4
|
+
attr_accessor :name, :value
|
5
|
+
|
6
|
+
QUERY_FILTERS = { access_token: 'token', source: 'source',
|
7
|
+
start_filter: 'start_date_filter',
|
8
|
+
end_filter: 'end_date_filter',
|
9
|
+
format_redirect: 'format',
|
10
|
+
sort: 'sort' }.freeze
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
@name = options[:name]
|
14
|
+
@value = options[:value]
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_hash
|
18
|
+
{ @name.to_sym => @value }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module V2Intuity
|
2
|
-
module
|
3
|
-
class Sort <
|
2
|
+
module QueryFilters
|
3
|
+
class Sort < QueryFilter
|
4
4
|
SORT = { dec_updated_at: '-updated_at', asc_updated_at: 'updated_at',
|
5
5
|
dec_created_at: '-created_at', asc_created_at: 'created_at' }.freeze
|
6
6
|
|
7
7
|
def initialize(options = {})
|
8
8
|
super
|
9
|
-
@name =
|
9
|
+
@name = QueryFilter::QUERY_FILTERS[:sort]
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module V2Intuity
|
2
|
+
module ResourceFilters # Stream resource query_filters that indicate what kind of data to be returned by stream. These are added to the body of the POST create stream endpoint
|
3
|
+
class ResourceFilter
|
4
|
+
attr_accessor :name
|
5
|
+
|
6
|
+
FILTERS = { measurement: 'measurement', nutrition: 'nutrition',
|
7
|
+
sleep: 'sleep', summaries: 'summaries',
|
8
|
+
workout: 'workout' }.freeze
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@name = options.fetch(options[:name], nil)
|
12
|
+
|
13
|
+
raise 'unsupported filter' unless @name.nil? && FILTERS.key?(@name.to_sym)
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -5,39 +5,66 @@ module V2Intuity
|
|
5
5
|
|
6
6
|
def initialize(options = {})
|
7
7
|
@name = options[:name]
|
8
|
-
@start_date = options.fetch(:start_date, Time.now.strftime('%Y-%d
|
9
|
-
|
10
|
-
@resource_filters =
|
8
|
+
@start_date = options.fetch(:start_date, Time.now.strftime('%Y-%m-%d'))
|
9
|
+
|
10
|
+
@resource_filters = format_resource_filters(options.fetch(:resource_filters, nil))
|
11
11
|
@stream_id = options[:stream_id]
|
12
12
|
end
|
13
13
|
|
14
|
-
def send_request(method, client
|
14
|
+
def send_request(method, client)
|
15
|
+
return 'StreamApi client is requied' unless client.class == V2Intuity::Clients::StreamApi
|
16
|
+
|
15
17
|
endpoint, options = build_options(method)
|
16
18
|
client.build_and_send_request(endpoint, options)
|
17
19
|
end
|
18
20
|
|
19
|
-
|
21
|
+
private
|
22
|
+
|
23
|
+
def build_options(method, query_filters = [])
|
20
24
|
case method
|
21
25
|
when V2Intuity::Request::METHODS[:delete]
|
22
|
-
raise 'stream id is needed' unless
|
26
|
+
raise 'stream id is needed' unless stream_id
|
23
27
|
options = { method: method, id: stream_id }
|
28
|
+
|
24
29
|
when V2Intuity::Request::METHODS[:get]
|
25
30
|
options = { method: method, id: stream_id }.compact # id can be blank when getting all streams
|
31
|
+
|
26
32
|
when V2Intuity::Request::METHODS[:post]
|
33
|
+
raise 'name is required' unless name
|
27
34
|
body = { name: name, start_date: start_date,
|
28
|
-
resource_filters: resource_filters } # supported
|
35
|
+
resource_filters: resource_filters }.compact # supported resource_query_filters include measurement, nutrition, sleep, workout
|
29
36
|
options = { method: method, body: body.compact }
|
37
|
+
|
30
38
|
when V2Intuity::Request::METHODS[:put]
|
31
|
-
raise 'stream id is needed' unless
|
39
|
+
raise 'stream id is needed' unless stream_id
|
32
40
|
body = { name: name }
|
33
41
|
options = { method: method, body: body.compact, id: stream_id }
|
42
|
+
|
34
43
|
else
|
35
44
|
raise 'incorrect method verb'
|
45
|
+
|
36
46
|
end
|
37
|
-
options[:
|
47
|
+
options[:query_filters] = query_filters unless query_filters.to_s.nil?
|
38
48
|
|
39
49
|
[V2Intuity::Endpoints::Stream.new, options]
|
40
50
|
end
|
51
|
+
|
52
|
+
def format_resource_filters(filters)
|
53
|
+
return nil unless filters
|
54
|
+
|
55
|
+
filters = filters.is_a?(Array) ? filters : [filters]
|
56
|
+
|
57
|
+
filters.each do |filter|
|
58
|
+
filter_class = filter.class
|
59
|
+
next if filter_class < V2Intuity::ResourceFilters::ResourceFilter || filter_class == V2Intuity::ResourceFilters::ResourceFilter
|
60
|
+
raise 'unsupported filter'
|
61
|
+
end
|
62
|
+
|
63
|
+
filter_array = []
|
64
|
+
filters.each { |filter| filter_array << filter.name }
|
65
|
+
|
66
|
+
filter_array.uniq
|
67
|
+
end
|
41
68
|
end
|
42
69
|
end
|
43
70
|
end
|
@@ -11,31 +11,11 @@ module V2Intuity
|
|
11
11
|
@country_code = options.fetch(:country_code, nil)
|
12
12
|
end
|
13
13
|
|
14
|
-
def send_request(method)
|
14
|
+
def send_request(method, client)
|
15
15
|
endpoint, options = build_options(method)
|
16
16
|
client.build_and_send_request(endpoint, options)
|
17
17
|
end
|
18
18
|
|
19
|
-
def build_options(method, filters = [])
|
20
|
-
raise 'uid is required' unless uid
|
21
|
-
|
22
|
-
case method
|
23
|
-
when V2Intuity::Request::METHODS[:delete], V2Intuity::Request::METHODS[:get]
|
24
|
-
options = { method: method, id: uid }
|
25
|
-
when V2Intuity::Request::METHODS[:post]
|
26
|
-
body = { id: uid, location: { timezone: time_zone, country_code: country_code }.compact }
|
27
|
-
options = { method: method, body: body.compact }
|
28
|
-
when V2Intuity::Request::METHODS[:put]
|
29
|
-
body = { location: { timezone: time_zone, country_code: country_code }.compact }
|
30
|
-
options = { method: method, body: body.compact, id: uid }
|
31
|
-
else
|
32
|
-
raise 'incorrect method verb'
|
33
|
-
end
|
34
|
-
options[:filters] = filters unless filters.to_s.nil?
|
35
|
-
|
36
|
-
[V2Intuity::Endpoints::User.new, options]
|
37
|
-
end
|
38
|
-
|
39
19
|
# method refreshes marketplace user token.
|
40
20
|
def refresh_marketplace(client)
|
41
21
|
raise 'uid is required' unless uid
|
@@ -55,17 +35,40 @@ module V2Intuity
|
|
55
35
|
client.build_and_send_request(endpoint, options)
|
56
36
|
end
|
57
37
|
|
38
|
+
private
|
39
|
+
|
58
40
|
def build_options_marketplace(token, format_redirect, redirect_uri) # marketplace user defined token
|
59
|
-
|
60
|
-
|
61
|
-
|
41
|
+
query_filters = []
|
42
|
+
query_filters << V2Intuity::QueryFilters::AccessToken.new(value: token)
|
43
|
+
query_filters << V2Intuity::QueryFilters::FormatRedirect.new(value: format_redirect)
|
62
44
|
|
63
|
-
options = {
|
45
|
+
options = { query_filters: query_filters, method: V2Intuity::Request::METHODS[:get] }
|
64
46
|
endpoint = V2Intuity::Endpoints::Marketplace.new
|
65
|
-
endpoint.define_redirect_uri(redirect_uri)
|
47
|
+
endpoint.define_redirect_uri(redirect_uri) ## overrides client's base_uri
|
66
48
|
|
67
49
|
[endpoint, options]
|
68
50
|
end
|
51
|
+
|
52
|
+
|
53
|
+
def build_options(method, query_filters = [])
|
54
|
+
raise 'uid is required' unless uid
|
55
|
+
|
56
|
+
case method
|
57
|
+
when V2Intuity::Request::METHODS[:delete], V2Intuity::Request::METHODS[:get]
|
58
|
+
options = { method: method, id: uid }
|
59
|
+
when V2Intuity::Request::METHODS[:post]
|
60
|
+
body = { uid: uid, location: { timezone: time_zone, country_code: country_code }.compact }
|
61
|
+
options = { method: method, body: body.compact }
|
62
|
+
when V2Intuity::Request::METHODS[:put]
|
63
|
+
body = { location: { timezone: time_zone, country_code: country_code }.compact }
|
64
|
+
options = { method: method, body: body.compact, id: uid }
|
65
|
+
else
|
66
|
+
raise 'incorrect method verb'
|
67
|
+
end
|
68
|
+
options[:query_filters] = query_filters unless query_filters.to_s.nil?
|
69
|
+
|
70
|
+
[V2Intuity::Endpoints::User.new, options]
|
71
|
+
end
|
69
72
|
end
|
70
73
|
end
|
71
74
|
end
|
data/lib/v2_intuity/version.rb
CHANGED
data/lib/v2_intuity.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
require 'requirements'
|
2
2
|
|
3
3
|
module V2Intuity
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
include V2Intuity::Clients
|
5
|
+
include V2Intuity::Users
|
6
|
+
include V2Intuity::Streams
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
class << self
|
9
|
+
attr_accessor :rest_uri, :token,
|
10
|
+
:stream_uri, :org_id
|
11
|
+
|
12
|
+
def configure
|
13
|
+
yield self
|
14
|
+
true
|
12
15
|
end
|
16
|
+
end
|
13
17
|
end
|
data/v2_intuity.gemspec
CHANGED
@@ -4,26 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'v2_intuity/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'v2_intuity'
|
8
8
|
spec.version = V2Intuity::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['rruiz858']
|
10
|
+
spec.email = ['rruiz@ncsu.edu']
|
11
11
|
|
12
|
-
spec.summary =
|
12
|
+
spec.summary = 'V2Intuity is a ruby wrapper to connecting to the new V2Intuity platform'
|
13
13
|
spec.description = "Wrapper allows one to manage V2Intuity's Rest API and even create/update/delete Streams. This is a work in progess and will not work, use other validic gem"
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
16
|
-
|
14
|
+
spec.homepage = ''
|
15
|
+
spec.license = 'MIT'
|
17
16
|
|
18
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
18
|
f.match(%r{^(test|spec|features)/})
|
20
19
|
end
|
21
|
-
spec.bindir =
|
20
|
+
spec.bindir = 'exe'
|
22
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ['lib']
|
24
23
|
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_dependency 'httparty', '~> 0.14.0'
|
29
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: v2_intuity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rruiz858
|
@@ -86,7 +86,9 @@ files:
|
|
86
86
|
- bin/setup
|
87
87
|
- lib/requirements.rb
|
88
88
|
- lib/v2_intuity.rb
|
89
|
-
- lib/v2_intuity/client.rb
|
89
|
+
- lib/v2_intuity/clients/client.rb
|
90
|
+
- lib/v2_intuity/clients/rest_api.rb
|
91
|
+
- lib/v2_intuity/clients/stream_api.rb
|
90
92
|
- lib/v2_intuity/endpoints/endpoint.rb
|
91
93
|
- lib/v2_intuity/endpoints/marketplace.rb
|
92
94
|
- lib/v2_intuity/endpoints/measurement.rb
|
@@ -96,24 +98,29 @@ files:
|
|
96
98
|
- lib/v2_intuity/endpoints/summary.rb
|
97
99
|
- lib/v2_intuity/endpoints/user.rb
|
98
100
|
- lib/v2_intuity/endpoints/workout.rb
|
99
|
-
- lib/v2_intuity/filters/access_token.rb
|
100
|
-
- lib/v2_intuity/filters/asc_created_at.rb
|
101
|
-
- lib/v2_intuity/filters/asc_updated_at.rb
|
102
|
-
- lib/v2_intuity/filters/date.rb
|
103
|
-
- lib/v2_intuity/filters/dec_created_at.rb
|
104
|
-
- lib/v2_intuity/filters/dec_updated_at.rb
|
105
|
-
- lib/v2_intuity/filters/end_date.rb
|
106
|
-
- lib/v2_intuity/filters/filter.rb
|
107
|
-
- lib/v2_intuity/filters/format_redirect.rb
|
108
|
-
- lib/v2_intuity/filters/resource_filters.rb
|
109
|
-
- lib/v2_intuity/filters/sort.rb
|
110
|
-
- lib/v2_intuity/filters/source.rb
|
111
|
-
- lib/v2_intuity/filters/start_date.rb
|
112
101
|
- lib/v2_intuity/headers/accept.rb
|
113
102
|
- lib/v2_intuity/headers/content_type.rb
|
114
103
|
- lib/v2_intuity/headers/header.rb
|
104
|
+
- lib/v2_intuity/query_filters/access_token.rb
|
105
|
+
- lib/v2_intuity/query_filters/asc_created_at.rb
|
106
|
+
- lib/v2_intuity/query_filters/asc_updated_at.rb
|
107
|
+
- lib/v2_intuity/query_filters/date.rb
|
108
|
+
- lib/v2_intuity/query_filters/dec_created_at.rb
|
109
|
+
- lib/v2_intuity/query_filters/dec_updated_at.rb
|
110
|
+
- lib/v2_intuity/query_filters/end_date.rb
|
111
|
+
- lib/v2_intuity/query_filters/filter.rb
|
112
|
+
- lib/v2_intuity/query_filters/format_redirect.rb
|
113
|
+
- lib/v2_intuity/query_filters/sort.rb
|
114
|
+
- lib/v2_intuity/query_filters/source.rb
|
115
|
+
- lib/v2_intuity/query_filters/start_date.rb
|
115
116
|
- lib/v2_intuity/request.rb
|
116
117
|
- lib/v2_intuity/request_error.rb
|
118
|
+
- lib/v2_intuity/resource_filters/measurement.rb
|
119
|
+
- lib/v2_intuity/resource_filters/nutrition.rb
|
120
|
+
- lib/v2_intuity/resource_filters/resource_filter.rb
|
121
|
+
- lib/v2_intuity/resource_filters/sleep.rb
|
122
|
+
- lib/v2_intuity/resource_filters/summary.rb
|
123
|
+
- lib/v2_intuity/resource_filters/workout.rb
|
117
124
|
- lib/v2_intuity/response.rb
|
118
125
|
- lib/v2_intuity/streams/stream.rb
|
119
126
|
- lib/v2_intuity/users/user.rb
|
data/lib/v2_intuity/client.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
module V2Intuity
|
3
|
-
class Client
|
4
|
-
attr_accessor :token, :org_id, :accept,
|
5
|
-
:content_type, :base_uri,
|
6
|
-
:httparty_client
|
7
|
-
|
8
|
-
def initialize(attributes = {})
|
9
|
-
required_fields(attributes)
|
10
|
-
@accept = attributes.fetch(:accept, 'application/json')
|
11
|
-
@content_type = attributes.fetch(:content_type, 'application/json')
|
12
|
-
end
|
13
|
-
|
14
|
-
def send_request(request)
|
15
|
-
case request.method
|
16
|
-
when V2Intuity::Request::METHODS[:get], V2Intuity::Request::METHODS[:delete]
|
17
|
-
@httparty_client.send(request.method.to_sym, request.uri, query: request.options[:filters], headers: request.options[:headers]) # puts re.request.last_uri.to_s
|
18
|
-
|
19
|
-
when V2Intuity::Request::METHODS[:post], V2Intuity::Request::METHODS[:put]
|
20
|
-
@httparty_client.send(request.method.to_sym, request.uri, query: request.options[:filters],
|
21
|
-
body: request.options[:body].to_json,
|
22
|
-
headers: request.options[:headers])
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def build_and_send_request(endpoint, options = {})
|
27
|
-
@request = build_request(endpoint, options)
|
28
|
-
send_request_generate_response(@request)
|
29
|
-
end
|
30
|
-
|
31
|
-
def build_request(endpoint, options = {})
|
32
|
-
http_party_options = {}
|
33
|
-
@filters = {}
|
34
|
-
@headers = {}
|
35
|
-
|
36
|
-
method = options[:method].to_s.nil? ? V2Intuity::Request::METHODS[:get] : options[:method]
|
37
|
-
id = options[:id].to_s.nil? ? nil : options[:id]
|
38
|
-
|
39
|
-
filters, headers = combine_filters_and_headers(options)
|
40
|
-
|
41
|
-
http_party_options[:filters] = filters
|
42
|
-
http_party_options[:headers] = headers
|
43
|
-
http_party_options[:body] = options[:body] unless method == V2Intuity::Request::METHODS[:get]
|
44
|
-
uri = endpoint.uri(org_id: org_id, id: id, base_uri: base_uri)
|
45
|
-
|
46
|
-
V2Intuity::Request.new(method: method, uri: uri, options: http_party_options)
|
47
|
-
end
|
48
|
-
|
49
|
-
def send_request_generate_response(request)
|
50
|
-
response = V2Intuity::Response.new(request: request)
|
51
|
-
|
52
|
-
self.httparty_client ||= HTTParty
|
53
|
-
response.define_response_and_json(send_request(request))
|
54
|
-
|
55
|
-
return response if response.response.success?
|
56
|
-
|
57
|
-
error = build_error(response)
|
58
|
-
|
59
|
-
response.add_errors(error)
|
60
|
-
|
61
|
-
response
|
62
|
-
|
63
|
-
rescue StandardError => e
|
64
|
-
response.add_errors(RequestError.new(code: 400, message: e.message))
|
65
|
-
|
66
|
-
response
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
def build_error(response)
|
72
|
-
json = response.json
|
73
|
-
if json
|
74
|
-
V2Intuity::RequestError.new(code: response.code, message: response.message, description: json['message'])
|
75
|
-
else
|
76
|
-
V2Intuity::RequestError.new(code: response.code, message: response.message)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def required_fields(attributes)
|
81
|
-
@token = attributes[:token]
|
82
|
-
raise 'Client requires token' unless @token
|
83
|
-
|
84
|
-
@org_id = attributes[:org_id]
|
85
|
-
raise 'Client requires org_id' unless @org_id
|
86
|
-
|
87
|
-
@base_uri = attributes[:base_uri]
|
88
|
-
raise 'Client requires base_uri' unless @base_uri
|
89
|
-
end
|
90
|
-
|
91
|
-
def default_filters
|
92
|
-
[V2Intuity::Filters::AccessToken.new(value: @token)]
|
93
|
-
end
|
94
|
-
|
95
|
-
def default_headers
|
96
|
-
[V2Intuity::Headers::Accept.new(value: @accept), V2Intuity::Headers::ContentType.new(value: @content_type)]
|
97
|
-
end
|
98
|
-
|
99
|
-
def combine_filters_and_headers(options)
|
100
|
-
total_filters = {}
|
101
|
-
total_headers = {}
|
102
|
-
filter_array = options[:filters].is_a?(Array) ? options[:filters] : []
|
103
|
-
header_array = options[:headers].is_a?(Array) ? options[:headers] : []
|
104
|
-
|
105
|
-
unique_filters = (default_filters + filter_array)
|
106
|
-
unique_filters.each do |filter|
|
107
|
-
total_filters.merge!(filter.to_hash)
|
108
|
-
end
|
109
|
-
|
110
|
-
unique_headers = (default_headers + header_array)
|
111
|
-
unique_headers.each do |header|
|
112
|
-
total_headers.merge!(header.to_hash)
|
113
|
-
end
|
114
|
-
|
115
|
-
[total_filters, total_headers]
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module V2Intuity
|
2
|
-
module Filters
|
3
|
-
class Filter
|
4
|
-
attr_accessor :name, :value
|
5
|
-
|
6
|
-
FILTERS = { access_token: 'token', source: 'source',
|
7
|
-
start_filter: 'start_date_filter',
|
8
|
-
end_filter: 'end_date_filter',
|
9
|
-
format_redirect: 'format',
|
10
|
-
sort: 'sort' }.freeze
|
11
|
-
|
12
|
-
def initialize(options = {})
|
13
|
-
@name = options[:name]
|
14
|
-
@value = options[:value]
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_hash
|
18
|
-
{ @name.to_sym => @value }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module V2Intuity
|
2
|
-
module Filters
|
3
|
-
class ResourceFilter # Strean resource filters that indicate what kind of data to be returned by stream
|
4
|
-
attr_accessor :name, :value
|
5
|
-
|
6
|
-
FILTERS = { measurement: 'measurement', nutrition: 'nutrition',
|
7
|
-
sleep: 'sleep', summaries: 'summaries',
|
8
|
-
workout: 'workout' }.freeze
|
9
|
-
|
10
|
-
def initialize(options = {})
|
11
|
-
@name = options[:name]
|
12
|
-
@value = options[:value]
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_hash
|
16
|
-
{ @name.to_sym => @value }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|