class Tinderbot::Client
Constants
- CONNECTION_USER_AGENT
- TINDER_API_URL
Attributes
connection[RW]
logs_enabled[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/tinderbot/client.rb, line 8 def initialize(options = {}) @logs_enabled = options[:logs_enabled] build_connection end
Public Instance Methods
dislike(user_or_user_id)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/tinderbot/client.rb, line 70 def send_message(user_id, message) @connection.post("user/matches/#{user_id}", {message: message}) puts "Sent message to #{user_id}" if @logs_enabled end
sign_in(authentication_token)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/tinderbot/client.rb, line 30 def updates JSON.parse(@connection.post('updates').body) end
user(user_id)
click to toggle source
# 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
Protected Instance Methods
build_connection()
click to toggle source
# File lib/tinderbot/client.rb, line 106 def build_connection @connection = Faraday.new(url: TINDER_API_URL) do |faraday| faraday.request :json faraday.adapter Faraday.default_adapter end @connection.headers[:user_agent] = CONNECTION_USER_AGENT end
dislike_from_user_id(user_id)
click to toggle source
# File lib/tinderbot/client.rb, line 98 def dislike_from_user_id(user_id) @connection.get "pass/#{user_id}" end
like_from_user_id(user_id)
click to toggle source
# File lib/tinderbot/client.rb, line 94 def like_from_user_id(user_id) @connection.get "like/#{user_id}" end
remove_from_user_id(user_id)
click to toggle source
# File lib/tinderbot/client.rb, line 102 def remove_from_user_id(user_id) @connection.delete "user/matches/#{user_id}" end