Class: TryTerra::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/try_terra/client.rb

Constant Summary collapse

BASE_URL =
"https://api.tryterra.co/v2/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dev_id:, x_api_key:, stubs: nil) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/try_terra/client.rb', line 7

def initialize(dev_id:, x_api_key:, stubs: nil)
  @dev_id = dev_id
  @x_api_key = x_api_key
  @stubs = stubs
end

Instance Attribute Details

#dev_idObject (readonly)

Returns the value of attribute dev_id.



5
6
7
# File 'lib/try_terra/client.rb', line 5

def dev_id
  @dev_id
end

#stubsObject (readonly)

Returns the value of attribute stubs.



5
6
7
# File 'lib/try_terra/client.rb', line 5

def stubs
  @stubs
end

#x_api_keyObject (readonly)

Returns the value of attribute x_api_key.



5
6
7
# File 'lib/try_terra/client.rb', line 5

def x_api_key
  @x_api_key
end

Instance Method Details

#activity(**params) ⇒ Object



29
30
31
# File 'lib/try_terra/client.rb', line 29

def activity(**params)
  ActivityResource.new(self).get(params)
end

#athlete(**params) ⇒ Object



25
26
27
# File 'lib/try_terra/client.rb', line 25

def athlete(**params)
  AthleteResource.new(self).get(params)
end

#authObject



13
14
15
# File 'lib/try_terra/client.rb', line 13

def auth
  AuthResource.new(self)
end

#body(**params) ⇒ Object



33
34
35
# File 'lib/try_terra/client.rb', line 33

def body(**params)
  BodyResource.new(self).get(params)
end

#connectionObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/try_terra/client.rb', line 49

def connection
  @connection ||= Faraday.new(BASE_URL) do |conn|
    conn.headers["dev-id"] = dev_id
    conn.headers["x-api-key"] = x_api_key

    conn.response :json, content_type: "application/json"
    # for testing
    if @stubs
      conn.adapter :test, @stubs
    end
  end
end

#daily(**params) ⇒ Object



37
38
39
# File 'lib/try_terra/client.rb', line 37

def daily(**params)
  DailyResource.new(self).get(params)
end

#menstruation(**params) ⇒ Object



45
46
47
# File 'lib/try_terra/client.rb', line 45

def menstruation(**params)
  MenstruationResource.new(self).get(params)
end

#sleep(**params) ⇒ Object



41
42
43
# File 'lib/try_terra/client.rb', line 41

def sleep(**params)
  SleepResource.new(self).get(params)
end

#subscriptions(**params) ⇒ Object



17
18
19
# File 'lib/try_terra/client.rb', line 17

def subscriptions(**params)
  SubscriptionsResource.new(self).get(params)
end

#user_info(**params) ⇒ Object



21
22
23
# File 'lib/try_terra/client.rb', line 21

def (**params)
  UserInfoResource.new(self).get(params)
end