Class: V2Intuity::Endpoints::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/v2_intuity/endpoints/endpoint.rb

Direct Known Subclasses

Marketplace, Measurement, Nutrition, Sleep, Stream, Summary, User, Workout

Constant Summary collapse

ENDPOINTS =
{ measurements: 'measurements', sleeps: 'sleeps',
nutrition: 'nutrition', summaries: 'summaries',
workouts: 'workouts', users: 'users',
marketplace: 'marketplace', streams: 'streams' }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Endpoint

Returns a new instance of Endpoint.



11
12
13
14
15
16
# File 'lib/v2_intuity/endpoints/endpoint.rb', line 11

def initialize(options = {})
  @endpoint = options[:endpoint]
  @path = options.fetch(:path, 'organizations')
  @id = options[:id]
  add_constants(options)
end

Instance Attribute Details

#base_uriObject

Returns the value of attribute base_uri.



4
5
6
# File 'lib/v2_intuity/endpoints/endpoint.rb', line 4

def base_uri
  @base_uri
end

#endpointObject

Returns the value of attribute endpoint.



4
5
6
# File 'lib/v2_intuity/endpoints/endpoint.rb', line 4

def endpoint
  @endpoint
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/v2_intuity/endpoints/endpoint.rb', line 4

def id
  @id
end

#org_idObject

Returns the value of attribute org_id.



4
5
6
# File 'lib/v2_intuity/endpoints/endpoint.rb', line 4

def org_id
  @org_id
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/v2_intuity/endpoints/endpoint.rb', line 4

def path
  @path
end

#tokenObject

Returns the value of attribute token.



4
5
6
# File 'lib/v2_intuity/endpoints/endpoint.rb', line 4

def token
  @token
end

Instance Method Details

#sign_withObject



36
37
38
# File 'lib/v2_intuity/endpoints/endpoint.rb', line 36

def sign_with
  [:access_token]
end

#uri(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/v2_intuity/endpoints/endpoint.rb', line 18

def uri(options = {})
  uri_options(options)
  if @id.nil?
    "#{@base_uri}/#{@path}/#{@org_id}/#{@endpoint}"
  else
    "#{@base_uri}/#{@path}/#{@org_id}/users/#{@id}/#{@endpoint}"
  end
end

#uri_options(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/v2_intuity/endpoints/endpoint.rb', line 27

def uri_options(options = {})
  @base_uri ||= options[:base_uri]
  @org_id ||= options[:org_id]
  @id ||= options[:id]

  raise 'org_id is needed' unless @org_id
  raise 'base_uri is needed' unless @base_uri
end