tinderbot 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/tinderbot/bot.rb +17 -0
- data/lib/tinderbot/cli/application.rb +2 -2
- data/lib/tinderbot/client.rb +98 -0
- data/lib/tinderbot/model/user.rb +33 -0
- data/lib/tinderbot/version.rb +1 -1
- data/spec/models/user_spec.rb +3 -3
- data/spec/spec_helper.rb +3 -0
- data/spec/tinder/bot_spec.rb +13 -13
- data/spec/tinder/client_spec.rb +9 -9
- data/tinderbot.gemspec +1 -0
- metadata +18 -4
- data/lib/tinderbot/tinder/bot.rb +0 -19
- data/lib/tinderbot/tinder/client.rb +0 -100
- data/lib/tinderbot/tinder/models/user.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7996ea7e4ff30a49b7ad49ab8406297e99f2e69e
|
4
|
+
data.tar.gz: cdcd1fca2d274daf3502bd9158a86c7a6351981d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c26988c78c633378fd7def83ae8ac253d59ff35766777f04eae3966a12722eb13add88032d461cb3ae39069f55525813bc7f0960e824519c688d08516af08729
|
7
|
+
data.tar.gz: bcdccdc21ecd381ccef1946b60e43e4d5ee3441937fd261c276226bce26b781a5caf508b64fae070d52975f57d2fcfaa7f59827063cdf7068c3c33ed46589f97
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Tinderbot
|
2
2
|
|
3
|
-
[](https://travis-ci.org/jvenezia/tinderbot)
|
4
3
|
[](http://badge.fury.io/rb/tinderbot)
|
4
|
+
[](https://travis-ci.org/jvenezia/tinderbot)
|
5
|
+
[](https://coveralls.io/r/jvenezia/tinderbot)
|
5
6
|
|
6
7
|
Tinderbot is a ruby wrapper for the Tinder API.
|
7
8
|
|
@@ -45,7 +46,7 @@ Once you get your credentials, you can sign in to Tinder.
|
|
45
46
|
facebook_authentication_token = 'your facebook authentication token'
|
46
47
|
facebook_user_id = 'your facebook user id'
|
47
48
|
|
48
|
-
tinder_client = Tinderbot::
|
49
|
+
tinder_client = Tinderbot::Client.new
|
49
50
|
tinder_authentication_token = tinder_client.get_authentication_token(facebook_authentication_token, facebook_user_id)
|
50
51
|
tinder_client.sign_in tinder_authentication_token
|
51
52
|
```
|
@@ -61,9 +62,9 @@ user.birth_date #=> #<Date: 2014-05-01>
|
|
61
62
|
user.gender #=> :male (or :female)
|
62
63
|
user.photo_urls #=> ['http://photo_1_url.jpg', 'http://photo_2_url.jpg']
|
63
64
|
|
64
|
-
user = tinder_client.user(user_id) #=> returns an instance of Tinderbot::
|
65
|
+
user = tinder_client.user(user_id) #=> returns an instance of Tinderbot::Model::User
|
65
66
|
|
66
|
-
users = tinder_client.recommended_users #=> returns an array of Tinderbot::
|
67
|
+
users = tinder_client.recommended_users #=> returns an array of Tinderbot::Model::User instances
|
67
68
|
|
68
69
|
tinder_client.updates #=> {...} original json from tinder's API
|
69
70
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Tinderbot
|
2
|
+
class Bot
|
3
|
+
attr_accessor :client
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
def like_recommended_users
|
10
|
+
recommended_users = @client.recommended_users
|
11
|
+
while recommended_users
|
12
|
+
recommended_users.each { |user| @client.like user }
|
13
|
+
recommended_users = @client.recommended_users
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -58,7 +58,7 @@ module Tinderbot
|
|
58
58
|
tinder_client = sign_in
|
59
59
|
|
60
60
|
puts 'Starting likes...'
|
61
|
-
tinder_bot = Tinderbot::
|
61
|
+
tinder_bot = Tinderbot::Bot.new tinder_client
|
62
62
|
tinder_bot.like_recommended_users
|
63
63
|
end
|
64
64
|
|
@@ -66,7 +66,7 @@ module Tinderbot
|
|
66
66
|
|
67
67
|
def sign_in
|
68
68
|
puts 'Connecting to tinder...'
|
69
|
-
tinder_client = Tinderbot::
|
69
|
+
tinder_client = Tinderbot::Client.new logs_enabled: true
|
70
70
|
store = PStore.new(FACEBOOK_CREDENTIALS_FILE)
|
71
71
|
facebook_authentication_token, facebook_user_id = get_last_facebook_credentials(store)
|
72
72
|
tinder_authentication_token = get_tinder_authentication_token(store, tinder_client, facebook_authentication_token, facebook_user_id)
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Tinderbot
|
2
|
+
class Client
|
3
|
+
TINDER_API_URL = 'https://api.gotinder.com'
|
4
|
+
CONNECTION_USER_AGENT = 'Tinder/3.0.4 (iPhone; iOS 7.1; Scale/2.00)'
|
5
|
+
|
6
|
+
attr_accessor :connection, :logs_enabled
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@logs_enabled = options[:logs_enabled]
|
10
|
+
build_connection
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_authentication_token(facebook_authentication_token, facebook_user_id)
|
14
|
+
JSON.parse(@connection.post('/auth', {facebook_token: facebook_authentication_token, facebook_id: facebook_user_id}).body)['token']
|
15
|
+
end
|
16
|
+
|
17
|
+
def sign_in(authentication_token)
|
18
|
+
@connection.token_auth(authentication_token)
|
19
|
+
@connection.headers['X-Auth-Token'] = authentication_token
|
20
|
+
end
|
21
|
+
|
22
|
+
def profile
|
23
|
+
Tinderbot::Model::User.build_from_tinder_json JSON.parse(@connection.get('profile').body)
|
24
|
+
end
|
25
|
+
|
26
|
+
def user(user_id)
|
27
|
+
Tinderbot::Model::User.build_from_tinder_json JSON.parse(@connection.get("user/#{user_id}").body)['results']
|
28
|
+
end
|
29
|
+
|
30
|
+
def updates
|
31
|
+
JSON.parse(@connection.post('updates').body)
|
32
|
+
end
|
33
|
+
|
34
|
+
def recommended_users
|
35
|
+
JSON.parse(@connection.post('user/recs').body)['results'].map { |r| Tinderbot::Model::User.build_from_tinder_json r }
|
36
|
+
end
|
37
|
+
|
38
|
+
def like(user_or_user_id)
|
39
|
+
if user_or_user_id.is_a? Tinderbot::Model::User
|
40
|
+
like_from_user_id(user_or_user_id.id)
|
41
|
+
puts "Liked #{user_or_user_id.id} (#{user_or_user_id.name})" if @logs_enabled
|
42
|
+
else
|
43
|
+
like_from_user_id(user_or_user_id)
|
44
|
+
puts "Liked #{user_or_user_id}" if @logs_enabled
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def dislike(user_or_user_id)
|
49
|
+
if user_or_user_id.is_a? Tinderbot::Model::User
|
50
|
+
dislike_from_user_id(user_or_user_id.id)
|
51
|
+
puts "Disliked #{user_or_user_id.id} (#{user_or_user_id.name})" if @logs_enabled
|
52
|
+
else
|
53
|
+
dislike_from_user_id(user_or_user_id)
|
54
|
+
puts "Disliked #{user_or_user_id}" if @logs_enabled
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def send_message(user_id, message)
|
59
|
+
@connection.post("user/matches/#{user_id}", {message: message})
|
60
|
+
puts "Sent message to #{user_id}" if @logs_enabled
|
61
|
+
end
|
62
|
+
|
63
|
+
def update_location(location)
|
64
|
+
latitude = location.split(',')[0]
|
65
|
+
longitude = location.split(',')[1]
|
66
|
+
|
67
|
+
if latitude && longitude
|
68
|
+
result = JSON.parse(@connection.post('user/ping', {lat: latitude, lon: longitude}).body)
|
69
|
+
|
70
|
+
if result['status'] == 200
|
71
|
+
puts "Location has been updated to #{location}" if @logs_enabled
|
72
|
+
else
|
73
|
+
puts result['error'] if @logs_enabled
|
74
|
+
end
|
75
|
+
else
|
76
|
+
raise Tinderbot::Error, 'Invalid location provided'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
protected
|
81
|
+
|
82
|
+
def like_from_user_id(user_id)
|
83
|
+
@connection.get "like/#{user_id}"
|
84
|
+
end
|
85
|
+
|
86
|
+
def dislike_from_user_id(user_id)
|
87
|
+
@connection.get "pass/#{user_id}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def build_connection
|
91
|
+
@connection = Faraday.new(url: TINDER_API_URL) do |faraday|
|
92
|
+
faraday.request :json
|
93
|
+
faraday.adapter Faraday.default_adapter
|
94
|
+
end
|
95
|
+
@connection.headers[:user_agent] = CONNECTION_USER_AGENT
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Tinderbot
|
2
|
+
module Model
|
3
|
+
class User
|
4
|
+
attr_accessor :original_tinder_json, :id, :name, :bio, :birth_date, :gender, :photo_urls
|
5
|
+
|
6
|
+
def self.build_from_tinder_json(tinder_json)
|
7
|
+
user = self.new
|
8
|
+
user.original_tinder_json = tinder_json
|
9
|
+
user.id = tinder_json['_id']
|
10
|
+
user.name = tinder_json['name']
|
11
|
+
user.bio = tinder_json['bio']
|
12
|
+
user.birth_date = Date.parse tinder_json['birth_date']
|
13
|
+
user.gender = tinder_json['gender'] == 0 ? :male : :female
|
14
|
+
user.photo_urls = tinder_json['photos'].map { |t| t['url'] }
|
15
|
+
user
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_yaml_properties
|
19
|
+
instance_variables - [:@original_tinder_json]
|
20
|
+
end
|
21
|
+
|
22
|
+
def ==(other)
|
23
|
+
other.class == self.class && other.state == self.state
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def state
|
29
|
+
self.instance_variables.reject { |item| item == :@original_tinder_json }.map { |variable| self.instance_variable_get variable }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/tinderbot/version.rb
CHANGED
data/spec/models/user_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Tinderbot::
|
3
|
+
describe Tinderbot::Model::User do
|
4
4
|
describe '#build_from_tinder_json' do
|
5
5
|
let(:user_tinder_json) { JSON.parse(open('spec/fixtures/user.json').read)['results'] }
|
6
6
|
|
7
|
-
subject { Tinderbot::
|
7
|
+
subject { Tinderbot::Model::User.build_from_tinder_json user_tinder_json }
|
8
8
|
|
9
9
|
it { expect(subject.original_tinder_json).to eq user_tinder_json }
|
10
10
|
it { expect(subject.id).to eq user_tinder_json['_id'] }
|
@@ -25,7 +25,7 @@ describe Tinderbot::Tinder::Models::User do
|
|
25
25
|
|
26
26
|
describe '.to_yaml' do
|
27
27
|
let(:user_tinder_json) { JSON.parse(open('spec/fixtures/user.json').read)['results'] }
|
28
|
-
let(:user) { Tinderbot::
|
28
|
+
let(:user) { Tinderbot::Model::User.build_from_tinder_json user_tinder_json }
|
29
29
|
|
30
30
|
subject { user.to_yaml }
|
31
31
|
|
data/spec/spec_helper.rb
CHANGED
data/spec/tinder/bot_spec.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Tinderbot::
|
4
|
-
let(:tinder_client) { Tinderbot::
|
5
|
-
let(:tinder_bot) { Tinderbot::
|
3
|
+
describe Tinderbot::Bot do
|
4
|
+
let(:tinder_client) { Tinderbot::Client.new }
|
5
|
+
let(:tinder_bot) { Tinderbot::Bot.new(tinder_client) }
|
6
6
|
|
7
7
|
describe 'client' do
|
8
8
|
it { expect(tinder_bot.client).to eq tinder_client }
|
9
9
|
end
|
10
10
|
|
11
11
|
describe '.like_recommended_people' do
|
12
|
-
let(:recommended_users) { JSON.parse(open('spec/fixtures/recommended_users.json').read)['results'].each { |user| Tinderbot::
|
12
|
+
let(:recommended_users) { JSON.parse(open('spec/fixtures/recommended_users.json').read)['results'].each { |user| Tinderbot::Model::User.build_from_tinder_json user } }
|
13
13
|
|
14
14
|
context 'there is no recommended people' do
|
15
|
-
before { expect_any_instance_of(Tinderbot::
|
15
|
+
before { expect_any_instance_of(Tinderbot::Client).to receive(:recommended_users).and_return(nil) }
|
16
16
|
|
17
|
-
before { expect_any_instance_of(Tinderbot::
|
17
|
+
before { expect_any_instance_of(Tinderbot::Client).not_to receive(:like_all) }
|
18
18
|
|
19
19
|
it { tinder_bot.like_recommended_users }
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'there is one set of recommended people' do
|
23
|
-
before { expect_any_instance_of(Tinderbot::
|
24
|
-
before { expect_any_instance_of(Tinderbot::
|
23
|
+
before { expect_any_instance_of(Tinderbot::Client).to receive(:recommended_users).and_return(recommended_users) }
|
24
|
+
before { expect_any_instance_of(Tinderbot::Client).to receive(:recommended_users).and_return(nil) }
|
25
25
|
|
26
|
-
before { recommended_users.each { |user| expect_any_instance_of(Tinderbot::
|
26
|
+
before { recommended_users.each { |user| expect_any_instance_of(Tinderbot::Client).not_to receive(:like).with(user).exactly(1).times } }
|
27
27
|
|
28
28
|
it { tinder_bot.like_recommended_users }
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'there is two sets of recommended people' do
|
32
|
-
before { expect_any_instance_of(Tinderbot::
|
33
|
-
before { expect_any_instance_of(Tinderbot::
|
34
|
-
before { expect_any_instance_of(Tinderbot::
|
32
|
+
before { expect_any_instance_of(Tinderbot::Client).to receive(:recommended_users).and_return(recommended_users) }
|
33
|
+
before { expect_any_instance_of(Tinderbot::Client).to receive(:recommended_users).and_return(recommended_users) }
|
34
|
+
before { expect_any_instance_of(Tinderbot::Client).to receive(:recommended_users).and_return(nil) }
|
35
35
|
|
36
|
-
before { recommended_users.each { |user| expect_any_instance_of(Tinderbot::
|
36
|
+
before { recommended_users.each { |user| expect_any_instance_of(Tinderbot::Client).not_to receive(:like).with(user).exactly(2).times } }
|
37
37
|
|
38
38
|
it { tinder_bot.like_recommended_users }
|
39
39
|
end
|
data/spec/tinder/client_spec.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Tinderbot::
|
4
|
-
let(:tinder_client) { Tinderbot::
|
3
|
+
describe Tinderbot::Client do
|
4
|
+
let(:tinder_client) { Tinderbot::Client.new }
|
5
5
|
let(:connection) { tinder_client.connection }
|
6
6
|
|
7
7
|
describe '.connection' do
|
8
8
|
it { expect(connection).to be_a(Faraday::Connection) }
|
9
|
-
it { expect("#{connection.url_prefix.scheme}://#{connection.url_prefix.host}").to eq(Tinderbot::
|
10
|
-
it { expect(connection.headers[:user_agent]).to eq(Tinderbot::
|
9
|
+
it { expect("#{connection.url_prefix.scheme}://#{connection.url_prefix.host}").to eq(Tinderbot::Client::TINDER_API_URL) }
|
10
|
+
it { expect(connection.headers[:user_agent]).to eq(Tinderbot::Client::CONNECTION_USER_AGENT) }
|
11
11
|
end
|
12
12
|
|
13
13
|
describe '.profile' do
|
@@ -18,7 +18,7 @@ describe Tinderbot::Tinder::Client do
|
|
18
18
|
|
19
19
|
subject { tinder_client.profile }
|
20
20
|
|
21
|
-
it { should
|
21
|
+
it { should eq Tinderbot::Model::User.build_from_tinder_json(JSON.parse(me_tinder_raw_json)) }
|
22
22
|
end
|
23
23
|
|
24
24
|
describe '.user' do
|
@@ -30,7 +30,7 @@ describe Tinderbot::Tinder::Client do
|
|
30
30
|
|
31
31
|
subject { tinder_client.user user_id }
|
32
32
|
|
33
|
-
it { should
|
33
|
+
it { should eq Tinderbot::Model::User.build_from_tinder_json(JSON.parse(user_tinder_raw_json)['results']) }
|
34
34
|
end
|
35
35
|
|
36
36
|
describe '.updates' do
|
@@ -52,7 +52,7 @@ describe Tinderbot::Tinder::Client do
|
|
52
52
|
|
53
53
|
subject { tinder_client.recommended_users }
|
54
54
|
|
55
|
-
it { should
|
55
|
+
it { should eq JSON.parse(recommended_users_tinder_raw_json)['results'].map { |r| Tinderbot::Model::User.build_from_tinder_json r } }
|
56
56
|
end
|
57
57
|
|
58
58
|
describe '.like' do
|
@@ -66,7 +66,7 @@ describe Tinderbot::Tinder::Client do
|
|
66
66
|
|
67
67
|
context 'from user model' do
|
68
68
|
let(:user_tinder_json) { JSON.parse(open('spec/fixtures/user.json').read)['results'] }
|
69
|
-
let(:user) { Tinderbot::
|
69
|
+
let(:user) { Tinderbot::Model::User.build_from_tinder_json user_tinder_json }
|
70
70
|
|
71
71
|
before { expect(connection).to receive(:get).with("like/#{user.id}") }
|
72
72
|
|
@@ -85,7 +85,7 @@ describe Tinderbot::Tinder::Client do
|
|
85
85
|
|
86
86
|
context 'from user model' do
|
87
87
|
let(:user_tinder_json) { JSON.parse(open('spec/fixtures/user.json').read)['results'] }
|
88
|
-
let(:user) { Tinderbot::
|
88
|
+
let(:user) { Tinderbot::Model::User.build_from_tinder_json user_tinder_json }
|
89
89
|
|
90
90
|
before { expect(connection).to receive(:get).with("pass/#{user.id}") }
|
91
91
|
|
data/tinderbot.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
22
|
spec.add_development_dependency 'rake', '~> 10.3'
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
|
+
spec.add_development_dependency 'coveralls', '~> 0.7'
|
24
25
|
|
25
26
|
spec.add_dependency 'thor', '~> 0'
|
26
27
|
spec.add_dependency 'faraday', '~> 0'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tinderbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Venezia
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.7'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: thor
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,12 +152,12 @@ files:
|
|
138
152
|
- Rakefile
|
139
153
|
- bin/tinderbot
|
140
154
|
- lib/tinderbot.rb
|
155
|
+
- lib/tinderbot/bot.rb
|
141
156
|
- lib/tinderbot/cli/application.rb
|
157
|
+
- lib/tinderbot/client.rb
|
142
158
|
- lib/tinderbot/error.rb
|
143
159
|
- lib/tinderbot/facebook.rb
|
144
|
-
- lib/tinderbot/
|
145
|
-
- lib/tinderbot/tinder/client.rb
|
146
|
-
- lib/tinderbot/tinder/models/user.rb
|
160
|
+
- lib/tinderbot/model/user.rb
|
147
161
|
- lib/tinderbot/version.rb
|
148
162
|
- spec/fixtures/profile.json
|
149
163
|
- spec/fixtures/recommended_users.json
|
data/lib/tinderbot/tinder/bot.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Tinderbot
|
2
|
-
module Tinder
|
3
|
-
class Bot
|
4
|
-
attr_accessor :client
|
5
|
-
|
6
|
-
def initialize(client)
|
7
|
-
@client = client
|
8
|
-
end
|
9
|
-
|
10
|
-
def like_recommended_users
|
11
|
-
recommended_users = @client.recommended_users
|
12
|
-
while recommended_users
|
13
|
-
recommended_users.each { |user| @client.like user }
|
14
|
-
recommended_users = @client.recommended_users
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
module Tinderbot
|
2
|
-
module Tinder
|
3
|
-
class Client
|
4
|
-
TINDER_API_URL = 'https://api.gotinder.com'
|
5
|
-
CONNECTION_USER_AGENT = 'Tinder/3.0.4 (iPhone; iOS 7.1; Scale/2.00)'
|
6
|
-
|
7
|
-
attr_accessor :connection, :logs_enabled
|
8
|
-
|
9
|
-
def initialize(options = {})
|
10
|
-
@logs_enabled = options[:logs_enabled]
|
11
|
-
build_connection
|
12
|
-
end
|
13
|
-
|
14
|
-
def get_authentication_token(facebook_authentication_token, facebook_user_id)
|
15
|
-
JSON.parse(@connection.post('/auth', {facebook_token: facebook_authentication_token, facebook_id: facebook_user_id}).body)['token']
|
16
|
-
end
|
17
|
-
|
18
|
-
def sign_in(authentication_token)
|
19
|
-
@connection.token_auth(authentication_token)
|
20
|
-
@connection.headers['X-Auth-Token'] = authentication_token
|
21
|
-
end
|
22
|
-
|
23
|
-
def profile
|
24
|
-
Tinderbot::Tinder::Models::User.build_from_tinder_json JSON.parse(@connection.get('profile').body)
|
25
|
-
end
|
26
|
-
|
27
|
-
def user(user_id)
|
28
|
-
Tinderbot::Tinder::Models::User.build_from_tinder_json JSON.parse(@connection.get("user/#{user_id}").body)['results']
|
29
|
-
end
|
30
|
-
|
31
|
-
def updates
|
32
|
-
JSON.parse(@connection.post('updates').body)
|
33
|
-
end
|
34
|
-
|
35
|
-
def recommended_users
|
36
|
-
JSON.parse(@connection.post('user/recs').body)['results'].map { |r| Tinderbot::Tinder::Models::User.build_from_tinder_json r }
|
37
|
-
end
|
38
|
-
|
39
|
-
def like(user_or_user_id)
|
40
|
-
if user_or_user_id.is_a? Tinderbot::Tinder::Models::User
|
41
|
-
like_from_user_id(user_or_user_id.id)
|
42
|
-
puts "Liked #{user_or_user_id.id} (#{user_or_user_id.name})" if @logs_enabled
|
43
|
-
else
|
44
|
-
like_from_user_id(user_or_user_id)
|
45
|
-
puts "Liked #{user_or_user_id}" if @logs_enabled
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def dislike(user_or_user_id)
|
50
|
-
if user_or_user_id.is_a? Tinderbot::Tinder::Models::User
|
51
|
-
dislike_from_user_id(user_or_user_id.id)
|
52
|
-
puts "Disliked #{user_or_user_id.id} (#{user_or_user_id.name})" if @logs_enabled
|
53
|
-
else
|
54
|
-
dislike_from_user_id(user_or_user_id)
|
55
|
-
puts "Disliked #{user_or_user_id}" if @logs_enabled
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def send_message(user_id, message)
|
60
|
-
@connection.post("user/matches/#{user_id}", {message: message})
|
61
|
-
puts "Sent message to #{user_id}" if @logs_enabled
|
62
|
-
end
|
63
|
-
|
64
|
-
def update_location(location)
|
65
|
-
latitude = location.split(',')[0]
|
66
|
-
longitude = location.split(',')[1]
|
67
|
-
|
68
|
-
if latitude && longitude
|
69
|
-
result = JSON.parse(@connection.post('user/ping', {lat: latitude, lon: longitude}).body)
|
70
|
-
|
71
|
-
if result['status'] == 200
|
72
|
-
puts "Location has been updated to #{location}" if @logs_enabled
|
73
|
-
else
|
74
|
-
puts result['error'] if @logs_enabled
|
75
|
-
end
|
76
|
-
else
|
77
|
-
raise Tinderbot::Error, 'Invalid location provided'
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
protected
|
82
|
-
|
83
|
-
def like_from_user_id(user_id)
|
84
|
-
@connection.get "like/#{user_id}"
|
85
|
-
end
|
86
|
-
|
87
|
-
def dislike_from_user_id(user_id)
|
88
|
-
@connection.get "pass/#{user_id}"
|
89
|
-
end
|
90
|
-
|
91
|
-
def build_connection
|
92
|
-
@connection = Faraday.new(url: TINDER_API_URL) do |faraday|
|
93
|
-
faraday.request :json
|
94
|
-
faraday.adapter Faraday.default_adapter
|
95
|
-
end
|
96
|
-
@connection.headers[:user_agent] = CONNECTION_USER_AGENT
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Tinderbot
|
2
|
-
module Tinder
|
3
|
-
module Models
|
4
|
-
class User
|
5
|
-
attr_accessor :original_tinder_json, :id, :name, :bio, :birth_date, :gender, :photo_urls
|
6
|
-
|
7
|
-
def self.build_from_tinder_json(tinder_json)
|
8
|
-
user = self.new
|
9
|
-
user.original_tinder_json = tinder_json
|
10
|
-
user.id = tinder_json['_id']
|
11
|
-
user.name = tinder_json['name']
|
12
|
-
user.bio = tinder_json['bio']
|
13
|
-
user.birth_date = Date.parse tinder_json['birth_date']
|
14
|
-
user.gender = tinder_json['gender'] == 0 ? :male : :female
|
15
|
-
user.photo_urls = tinder_json['photos'].map { |t| t['url'] }
|
16
|
-
user
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_yaml_properties
|
20
|
-
instance_variables - [:@original_tinder_json]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|