Class: MShealth::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/MShealth/client.rb

Instance Method Summary collapse

Instance Method Details

#activities(start_time:, end_time:, **options) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/MShealth/client.rb', line 90

def activities(start_time:,end_time:,**options)
  query = {}

  query['startTime'] = start_time.iso8601
  query['endTime'] = end_time.iso8601
  query['activityTypes'] = options[:activity_types] if options.key?(:activity_types)
  query = handle_activity_include(query,options)

  response = response = handle_response("/"+configuration.api_version+"/me/Activities",
  :headers => {"Authorization" => "bearer "+configuration.token},
  :query => query)

  result = []

  types = ['bike','freePlay','golf','guidedWorkout','run','sleep']

  result = extract_activities(types,response,result)

  while response.key?("nextPage")
    response = handle_response(response['nextPage'],:headers => {"Authorization" => "bearer "+configuration.token})
    result = extract_activities(types,response,result)
  end

  result
end

#activity(id:, **options) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/MShealth/client.rb', line 78

def activity(id:,**options)
  query = {}
  query = handle_activity_include(query,options)

  response = handle_response("/"+configuration.api_version+"/me/Activities/"+id,
  :headers => {"Authorization" => "bearer "+configuration.token},
  :query => query)

  MShealth::Mash.new(response)

end

#configurationObject



11
12
13
# File 'lib/MShealth/client.rb', line 11

def configuration
  @configuration ||= Configuration.new
end

#configure {|configuration| ... } ⇒ Object

Yields:



15
16
17
# File 'lib/MShealth/client.rb', line 15

def configure
  yield configuration
end

#device(id:) ⇒ Object



35
36
37
38
39
# File 'lib/MShealth/client.rb', line 35

def device(id:)
  response = handle_response("/"+configuration.api_version+"/me/Devices/"+id,
  :headers => {"Authorization" => "bearer "+configuration.token})
  MShealth::Mash.new(response)
end

#devicesObject



25
26
27
28
29
30
31
32
33
# File 'lib/MShealth/client.rb', line 25

def devices
  response = handle_response("/"+configuration.api_version+"/me/Devices",
  :headers => {"Authorization" => "bearer "+configuration.token})
  devices = []
  response['deviceProfiles'].each do |device|
    devices << MShealth::Mash.new(device)
  end
  devices
end

#profileObject



19
20
21
22
23
# File 'lib/MShealth/client.rb', line 19

def profile
  response = handle_response("/"+configuration.api_version+"/me/Profile",
  :headers => {"Authorization" => "bearer "+configuration.token})
  MShealth::Mash.new(response)
end

#summary(period:, start_time:, **options) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/MShealth/client.rb', line 41

def summary(period:,start_time:,**options)
  query = {}
  query['startTime'] = start_time.iso8601
  query['endTime'] = options[:end_time].iso8601 if options.key?(:end_time)
  query['deviceIds'] = options[:device_id] if options.key?(:device_id)

  period_str = nil
  response = nil

  case period
  when "hourly"
    period_str = 'Hourly'
  when "daily"
    period_str = 'Daily'
  else
  end

  response = handle_response("/"+configuration.api_version+"/me/Summaries/"+period_str,
  :headers => {"Authorization" => "bearer "+configuration.token},
  :query => query)

  result = []

  response['summaries'].each do |summary|
    result << MShealth::Mash.new(summary)
  end

  while response.key?("nextPage")
    response = handle_response(response['nextPage'],:headers => {"Authorization" => "bearer "+configuration.token})
    response['summaries'].each do |summary|
      result << MShealth::Mash.new(summary)
    end
  end

  result
end