Class: Tinderbot::Client
- Inherits:
-
Object
- Object
- Tinderbot::Client
- Defined in:
- lib/tinderbot/client.rb
Constant Summary collapse
- TINDER_API_URL =
'https://api.gotinder.com'
- CONNECTION_USER_AGENT =
'Tinder/3.0.4 (iPhone; iOS 7.1; Scale/2.00)'
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#logs_enabled ⇒ Object
Returns the value of attribute logs_enabled.
Instance Method Summary collapse
- #dislike(user_or_user_id) ⇒ Object
- #get_authentication_token(facebook_authentication_token, facebook_user_id) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #like(user_or_user_id) ⇒ Object
- #profile ⇒ Object
- #recommended_users ⇒ Object
- #remove(user_or_user_id) ⇒ Object
- #send_message(user_id, message) ⇒ Object
- #sign_in(authentication_token) ⇒ Object
- #update_location(location) ⇒ Object
- #updates ⇒ Object
- #user(user_id) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 |
# File 'lib/tinderbot/client.rb', line 8 def initialize( = {}) @logs_enabled = [:logs_enabled] build_connection end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
6 7 8 |
# File 'lib/tinderbot/client.rb', line 6 def connection @connection end |
#logs_enabled ⇒ Object
Returns the value of attribute logs_enabled.
6 7 8 |
# File 'lib/tinderbot/client.rb', line 6 def logs_enabled @logs_enabled end |
Instance Method Details
#dislike(user_or_user_id) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/tinderbot/client.rb', line 50 def dislike(user_or_user_id) if user_or_user_id.is_a? Tinderbot::Model::User dislike_from_user_id(user_or_user_id.id) puts "Disliked #{user_or_user_id.id} (#{user_or_user_id.name})" if @logs_enabled else dislike_from_user_id(user_or_user_id) puts "Disliked #{user_or_user_id}" if @logs_enabled end end |
#get_authentication_token(facebook_authentication_token, facebook_user_id) ⇒ Object
13 14 15 |
# File 'lib/tinderbot/client.rb', line 13 def get_authentication_token(facebook_authentication_token, facebook_user_id) JSON.parse(@connection.post('/auth', {facebook_token: facebook_authentication_token, facebook_id: facebook_user_id}).body)['token'] end |
#like(user_or_user_id) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/tinderbot/client.rb', line 40 def like(user_or_user_id) if user_or_user_id.is_a? Tinderbot::Model::User like_from_user_id(user_or_user_id.id) puts "Liked #{user_or_user_id.id} (#{user_or_user_id.name})" if @logs_enabled else like_from_user_id(user_or_user_id) puts "Liked #{user_or_user_id}" if @logs_enabled end end |
#profile ⇒ Object
22 23 24 |
# File 'lib/tinderbot/client.rb', line 22 def profile Tinderbot::Model::User.build_from_tinder_json JSON.parse(@connection.get('profile').body) end |
#recommended_users ⇒ Object
34 35 36 37 38 |
# File 'lib/tinderbot/client.rb', line 34 def recommended_users json_results = JSON.parse(@connection.post('user/recs').body)['results'] users = json_results.select { |r| r['name'] != 'Tinder Team' }.map { |r| Tinderbot::Model::User.build_from_tinder_json r } if json_results users || [] end |
#remove(user_or_user_id) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/tinderbot/client.rb', line 60 def remove(user_or_user_id) if user_or_user_id.is_a? Tinderbot::Model::User remove_from_user_id(user_or_user_id.id) puts "Removed #{user_or_user_id.id} (#{user_or_user_id.name})" if @logs_enabled else remove_from_user_id(user_or_user_id) puts "Removed #{user_or_user_id}" if @logs_enabled end end |
#send_message(user_id, message) ⇒ Object
70 71 72 73 |
# File 'lib/tinderbot/client.rb', line 70 def (user_id, ) @connection.post("user/matches/#{user_id}", {message: }) puts "Sent message to #{user_id}" if @logs_enabled end |
#sign_in(authentication_token) ⇒ Object
17 18 19 20 |
# File 'lib/tinderbot/client.rb', line 17 def sign_in(authentication_token) @connection.token_auth(authentication_token) @connection.headers['X-Auth-Token'] = authentication_token end |
#update_location(location) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/tinderbot/client.rb', line 75 def update_location(location) latitude = location.split(',')[0] longitude = location.split(',')[1] if latitude && longitude result = JSON.parse(@connection.post('user/ping', {lat: latitude, lon: longitude}).body) if result['status'] == 200 puts "Location has been updated to #{location}" if @logs_enabled else puts result['error'] if @logs_enabled end else raise Tinderbot::Error, 'Invalid location provided' end end |
#updates ⇒ Object
30 31 32 |
# File 'lib/tinderbot/client.rb', line 30 def updates JSON.parse(@connection.post('updates').body) end |
#user(user_id) ⇒ Object
26 27 28 |
# File 'lib/tinderbot/client.rb', line 26 def user(user_id) Tinderbot::Model::User.build_from_tinder_json JSON.parse(@connection.get("user/#{user_id}").body)['results'] end |