Class: Liftapp::Client
- Inherits:
-
Object
- Object
- Liftapp::Client
- Defined in:
- lib/liftapp-client.rb,
lib/liftapp-client/version.rb
Constant Summary collapse
- VERSION =
"0.0.6"
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#picture_url ⇒ Object
readonly
Returns the value of attribute picture_url.
-
#profile_hash ⇒ Object
readonly
Returns the value of attribute profile_hash.
Instance Method Summary collapse
- #checkin(habit_id, instruction_id = nil, time = DateTime.now) ⇒ Object
- #checkin_data(habit_id) ⇒ Object
- #checkout(checkin_id) ⇒ Object
- #dashboard ⇒ Object
-
#initialize(email, password) ⇒ Client
constructor
A new instance of Client.
- #notifications ⇒ Object
-
#plan_questions(plan_id, opts) ⇒ Object
Example opts limit: 30, offset: 0.
- #plan_stats(plan_id) ⇒ Object
- #stats ⇒ Object
Constructor Details
#initialize(email, password) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/liftapp-client.rb', line 18 def initialize(email, password) @user_agent = 'Lift/0.27.1779 CFNetwork/609.1.4 Darwin/13.0.0' @auth_options = { basic_auth: { username: email, password: password } } @options = {} @options.merge!(@auth_options) @options.merge!({ headers: {'User-Agent' => @user_agent }}) response = HTTParty.get('https://www.lift.do/i/0/users/current', @options) raise AccessDenied, 'Invalid email/password' if response.response.code == '401' @email = response['email'] @profile_hash = response['profile_hash'] @picture_url = response['picture_url'] @name = response['name'] end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
16 17 18 |
# File 'lib/liftapp-client.rb', line 16 def email @email end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/liftapp-client.rb', line 14 def name @name end |
#picture_url ⇒ Object (readonly)
Returns the value of attribute picture_url.
15 16 17 |
# File 'lib/liftapp-client.rb', line 15 def picture_url @picture_url end |
#profile_hash ⇒ Object (readonly)
Returns the value of attribute profile_hash.
13 14 15 |
# File 'lib/liftapp-client.rb', line 13 def profile_hash @profile_hash end |
Instance Method Details
#checkin(habit_id, instruction_id = nil, time = DateTime.now) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/liftapp-client.rb', line 58 def checkin(habit_id, instruction_id=nil, time=DateTime.now) data = { body: { habit_id: habit_id, instruction_id: instruction_id, date: time.to_s } } HTTParty.post('https://www.lift.do/api/v3/checkins', @options.merge(data)) end |
#checkin_data(habit_id) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/liftapp-client.rb', line 69 def checkin_data(habit_id) response = HTTParty.get('https://www.lift.do/users/%s/%d' % [@profile_hash, habit_id]) doc = Nokogiri::HTML(response.body) month_names = doc.search('.calendar h3') month_tables = doc.search('#profile-calendar table.cal-month') checkins = [] while (!month_names.empty?) month_name = month_names.shift month_table = month_tables.shift month_table.search('div.checked').each do |day| m_day = day.text checkins.push(Date.parse(m_day + ' ' + month_name.content)) end end { 'habit-name' => doc.search('.profile-habit-name').first.content.strip, 'checkins' => checkins.sort } end |
#checkout(checkin_id) ⇒ Object
65 66 67 |
# File 'lib/liftapp-client.rb', line 65 def checkout(checkin_id) HTTParty.delete('https://www.lift.do/api/v3/checkins/%d' % checkin_id) end |
#dashboard ⇒ Object
37 38 39 |
# File 'lib/liftapp-client.rb', line 37 def dashboard HTTParty.get('https://www.lift.do/api/v4/dashboard', @options) end |
#notifications ⇒ Object
45 46 47 |
# File 'lib/liftapp-client.rb', line 45 def notifications HTTParty.get('https://www.lift.do/api/v3/notifications/', @options) end |
#plan_questions(plan_id, opts) ⇒ Object
Example opts limit: 30, offset: 0
50 51 52 |
# File 'lib/liftapp-client.rb', line 50 def plan_questions(plan_id, opts) HTTParty.get('https://www.lift.do/api/v3/plans/%d/questions' % plan_id, @options.merge(query: opts)) end |
#plan_stats(plan_id) ⇒ Object
54 55 56 |
# File 'lib/liftapp-client.rb', line 54 def plan_stats(plan_id) HTTParty.get('https://www.lift.do/api/v3/plans/%d/stats' % plan_id, @options) end |
#stats ⇒ Object
41 42 43 |
# File 'lib/liftapp-client.rb', line 41 def stats HTTParty.get('https://www.lift.do/api/v3/enrollments/stats', @options) end |