liftapp-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +28 -9
- data/Rakefile +5 -0
- data/examples/csv_export/Gemfile +3 -0
- data/examples/csv_export/app.rb +3 -2
- data/lib/liftapp-client/version.rb +1 -1
- data/lib/liftapp-client.rb +27 -21
- data/liftapp-client.gemspec +4 -1
- data/spec/lift_spec.rb +20 -6
- metadata +41 -3
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# Liftapp::Client
|
1
|
+
# Liftapp::Client [![Build Status](https://travis-ci.org/jmaddi/liftapp-client.png)](https://travis-ci.org/jmaddi/liftapp-client)
|
2
2
|
|
3
3
|
Ruby library to access the Lift.do API. Since there is not yet an official API, this library uses the undocumented mobile app API.
|
4
4
|
|
5
|
+
For an example of what you can build, see http://lift-export.herokuapp.com/
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
@@ -20,24 +22,41 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
##### Request your profile_hash
|
22
24
|
```ruby
|
23
|
-
|
24
|
-
|
25
|
-
puts
|
25
|
+
# Log in with your email/password
|
26
|
+
client = Liftapp::Client.new('neo@matrix.com', 'whiterabbit')
|
27
|
+
puts client.profile_hash
|
26
28
|
```
|
27
29
|
|
28
30
|
##### Request your subscribed habits
|
29
31
|
```ruby
|
30
|
-
client = Liftapp::Client.new(
|
32
|
+
client = Liftapp::Client.new('neo@matrix.com', 'whiterabbit')
|
31
33
|
data = client.dashboard
|
32
|
-
|
34
|
+
data['subscriptions'].each do |subscription|
|
35
|
+
puts subscription['habit']['name'] + ": " + subscription['habit']['id'].to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
Nightly survey: 75655
|
39
|
+
Write: 3280
|
40
|
+
Test Lift: 2111
|
41
|
+
Keep in touch with friends: 2829
|
42
|
+
Organize social event: 71452
|
33
43
|
```
|
34
44
|
|
35
45
|
##### Request checkin data for your habit
|
36
46
|
```ruby
|
37
|
-
client = Liftapp::Client.new(
|
47
|
+
client = Liftapp::Client.new('neo@matrix.com', 'whiterabbit')
|
38
48
|
data = client.checkin_data('3280')
|
39
|
-
puts data[
|
40
|
-
puts data[
|
49
|
+
puts data['checkins'].inspect
|
50
|
+
puts data['habit-name']
|
51
|
+
```
|
52
|
+
|
53
|
+
##### Checkin to a habit
|
54
|
+
```ruby
|
55
|
+
client = Liftapp::Client.new('neo@matrix.com', 'whiterabbit')
|
56
|
+
data = client.dashboard
|
57
|
+
puts data['subscriptions'][1]['habit']['name']
|
58
|
+
habit_id = data['subscriptions'][0]['habit']['id']
|
59
|
+
client.checkin(habit_id)
|
41
60
|
```
|
42
61
|
|
43
62
|
|
data/Rakefile
CHANGED
data/examples/csv_export/Gemfile
CHANGED
data/examples/csv_export/app.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'sinatra'
|
2
|
+
require 'haml'
|
2
3
|
require 'coffee-script'
|
3
4
|
require 'liftapp-client'
|
4
5
|
|
@@ -20,8 +21,8 @@ get '/checkins/:user/:habit' do
|
|
20
21
|
content_type :plain
|
21
22
|
client = Liftapp::Client.new(profile_hash: params[:user])
|
22
23
|
data = client.checkin_data(params[:habit])
|
23
|
-
output = data[
|
24
|
-
output.unshift data[
|
24
|
+
output = data['checkins'].map { |d| d.strftime('%Y-%m-%d') }
|
25
|
+
output.unshift data['habit-name']
|
25
26
|
output.join("\n")
|
26
27
|
end
|
27
28
|
|
data/lib/liftapp-client.rb
CHANGED
@@ -1,38 +1,48 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'json'
|
3
3
|
require 'nokogiri'
|
4
|
+
require 'date'
|
5
|
+
require 'pry'
|
4
6
|
|
5
7
|
require "liftapp-client/version"
|
6
8
|
|
7
9
|
module Liftapp
|
10
|
+
|
8
11
|
class Client
|
9
12
|
attr_accessor :profile_hash
|
10
13
|
|
11
|
-
def initialize(
|
12
|
-
@
|
13
|
-
@password = args[:password] if args[:password]
|
14
|
-
@profile_hash = args[:profile_hash] if args[:profile_hash]
|
15
|
-
if (@email && @password)
|
16
|
-
@auth_options = {basic_auth: {username: @email, password: @password}}
|
17
|
-
end
|
18
|
-
end
|
14
|
+
def initialize(email, password)
|
15
|
+
@user_agent = 'Lift/0.27.1779 CFNetwork/609.1.4 Darwin/13.0.0'
|
19
16
|
|
20
|
-
|
21
|
-
|
17
|
+
@auth_options = {basic_auth: {username: email, password: password}}
|
18
|
+
|
19
|
+
@options = {}
|
20
|
+
@options.merge!(@auth_options)
|
21
|
+
@options.merge!({headers: {'User-Agent' => @user_agent}})
|
22
|
+
|
23
|
+
response = HTTParty.get('https://www.lift.do/i/0/users/current', @options)
|
22
24
|
@profile_hash = response['profile_hash']
|
23
|
-
response
|
24
25
|
end
|
25
26
|
|
26
27
|
def dashboard
|
27
|
-
HTTParty.get('https://www.lift.do/api/v2/dashboard', @
|
28
|
+
HTTParty.get('https://www.lift.do/api/v2/dashboard', @options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def checkin(habit_id, time=DateTime.now)
|
32
|
+
data = {body: {habit_id: habit_id, date: time.to_s}}
|
33
|
+
HTTParty.post('https://www.lift.do/api/v1/checkins', @options.merge(data))
|
34
|
+
end
|
35
|
+
|
36
|
+
def checkout(checkin_id)
|
37
|
+
HTTParty.delete('https://www.lift.do/api/v1/checkins/%d' % checkin_id)
|
28
38
|
end
|
29
39
|
|
30
40
|
def habit_activity(habit_id)
|
31
|
-
HTTParty.get('https://www.lift.do/api/v2/habits/'
|
41
|
+
HTTParty.get('https://www.lift.do/api/v2/habits/%d/activity' % habit_id, @options)
|
32
42
|
end
|
33
43
|
|
34
44
|
def checkin_data(habit_id)
|
35
|
-
response = HTTParty.get('https://www.lift.do/users
|
45
|
+
response = HTTParty.get('https://www.lift.do/users/%s/%d' % [@profile_hash, habit_id])
|
36
46
|
|
37
47
|
doc = Nokogiri::HTML(response.body)
|
38
48
|
|
@@ -49,14 +59,10 @@ module Liftapp
|
|
49
59
|
end
|
50
60
|
end
|
51
61
|
{
|
52
|
-
|
53
|
-
|
62
|
+
'habit-name' => doc.search('.profile-habit-name').first.content,
|
63
|
+
'checkins' => checkins.sort
|
54
64
|
}
|
55
65
|
end
|
56
|
-
|
57
|
-
def to_s
|
58
|
-
"Liftapp (#@email)"
|
59
|
-
end
|
60
|
-
|
61
66
|
end
|
67
|
+
|
62
68
|
end
|
data/liftapp-client.gemspec
CHANGED
@@ -17,5 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
|
18
18
|
gem.add_dependency 'httparty'
|
19
19
|
gem.add_dependency 'nokogiri'
|
20
|
-
|
20
|
+
|
21
|
+
gem.add_development_dependency 'webmock'
|
22
|
+
gem.add_development_dependency 'rake'
|
23
|
+
gem.add_development_dependency 'rspec'
|
21
24
|
end
|
data/spec/lift_spec.rb
CHANGED
@@ -7,27 +7,41 @@ describe Liftapp::Client do
|
|
7
7
|
stub_request(:get, "https://neo@matrix.com:whiterabbit@www.lift.do/i/0/users/current").
|
8
8
|
to_return(File.new(File.expand_path File.dirname(__FILE__) + '/fixtures/current'))
|
9
9
|
|
10
|
-
client = Liftapp::Client.new(
|
11
|
-
expect(client.login['profile_hash']).to eq 'e7fcd2db926273e895ef'
|
10
|
+
client = Liftapp::Client.new('neo@matrix.com', 'whiterabbit')
|
12
11
|
expect(client.profile_hash).to eq 'e7fcd2db926273e895ef'
|
13
12
|
end
|
14
13
|
|
15
14
|
it 'returns habit list' do
|
15
|
+
stub_request(:get, "https://neo@matrix.com:whiterabbit@www.lift.do/i/0/users/current").
|
16
|
+
to_return(File.new(File.expand_path File.dirname(__FILE__) + '/fixtures/current'))
|
16
17
|
stub_request(:get, "https://neo@matrix.com:whiterabbit@www.lift.do/api/v2/dashboard").
|
17
18
|
to_return(File.new(File.expand_path File.dirname(__FILE__) + '/fixtures/dashboard'))
|
18
19
|
|
19
|
-
client = Liftapp::Client.new(
|
20
|
+
client = Liftapp::Client.new('neo@matrix.com', 'whiterabbit')
|
20
21
|
expect(client.dashboard['subscriptions'].length).to eq 7
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'returns checkin data' do
|
25
|
+
stub_request(:get, "https://neo@matrix.com:whiterabbit@www.lift.do/i/0/users/current").
|
26
|
+
to_return(File.new(File.expand_path File.dirname(__FILE__) + '/fixtures/current'))
|
24
27
|
stub_request(:get, "https://www.lift.do/users/e7fcd2db926273e895ef/3280").
|
25
28
|
to_return(File.new(File.expand_path File.dirname(__FILE__) + '/fixtures/3280'))
|
26
29
|
|
27
|
-
client = Liftapp::Client.new(
|
30
|
+
client = Liftapp::Client.new('neo@matrix.com', 'whiterabbit')
|
28
31
|
data = client.checkin_data('3280')
|
29
|
-
data[
|
30
|
-
data[
|
32
|
+
data['checkins'].length.should be > 10
|
33
|
+
data['habit-name'].should eq 'Write'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns successful checkin' do
|
37
|
+
stub_request(:get, "https://neo@matrix.com:whiterabbit@www.lift.do/i/0/users/current").
|
38
|
+
to_return(File.new(File.expand_path File.dirname(__FILE__) + '/fixtures/current'))
|
39
|
+
stub_request(:post, 'https://neo@matrix.com:whiterabbit@www.lift.do/api/v1/checkins').
|
40
|
+
to_return(File.new(File.expand_path File.dirname(__FILE__) + '/fixtures/checkin'))
|
41
|
+
|
42
|
+
client = Liftapp::Client.new('neo@matrix.com', 'whiterabbit')
|
43
|
+
data = client.checkin('2111')
|
44
|
+
data['checkin']['id'].should be > 0
|
31
45
|
end
|
32
46
|
|
33
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liftapp-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -51,7 +51,39 @@ dependencies:
|
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
|
-
type: :
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
55
87
|
prerelease: false
|
56
88
|
version_requirements: !ruby/object:Gem::Requirement
|
57
89
|
none: false
|
@@ -104,12 +136,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
136
|
- - ! '>='
|
105
137
|
- !ruby/object:Gem::Version
|
106
138
|
version: '0'
|
139
|
+
segments:
|
140
|
+
- 0
|
141
|
+
hash: -3304321220084016818
|
107
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
143
|
none: false
|
109
144
|
requirements:
|
110
145
|
- - ! '>='
|
111
146
|
- !ruby/object:Gem::Version
|
112
147
|
version: '0'
|
148
|
+
segments:
|
149
|
+
- 0
|
150
|
+
hash: -3304321220084016818
|
113
151
|
requirements: []
|
114
152
|
rubyforge_project:
|
115
153
|
rubygems_version: 1.8.21
|