class Tinby::Client

Constants

CONNECTION_USER_AGENT
TINDER_API_URL

Attributes

connection[R]
email[R]
logined[RW]
password[R]

Public Class Methods

new(email, password) click to toggle source
# File lib/tinby/client.rb, line 14
def initialize(email, password)
  @email = email
  @password = password
  @logined = false
  build_tinder_connection
end

Public Instance Methods

dislike(user_id) click to toggle source
# File lib/tinby/client.rb, line 48
def dislike(user_id)
  sign_in unless login?
  connection.get("pass/#{user_id}")
end
like(user_id) click to toggle source
# File lib/tinby/client.rb, line 43
def like(user_id)
  sign_in unless login?
  connection.get("like/#{user_id}")
end
matches() click to toggle source
# File lib/tinby/client.rb, line 37
def matches
  sign_in unless login?
  response = connection.post('updates', last_activity_date: '').body
  response ? JSON.parse(response) : []
end
profile() click to toggle source
# File lib/tinby/client.rb, line 21
def profile
  sign_in unless login?
  response = connection.get('profile').body
  raise Unauthorized if response == 'Unauthorized'
  JSON.parse(response, symbolize_names: true)
end
send_message(user_id, message) click to toggle source
# File lib/tinby/client.rb, line 53
def send_message(user_id, message)
  sign_in unless login?
  connection.post("user/matches/#{user_id}", message: message)
end

Private Instance Methods

auth_request() click to toggle source
# File lib/tinby/client.rb, line 74
def auth_request
  connection.post('/auth', facebook_token: facebook_authentication_token).body
end
build_tinder_connection() click to toggle source
# File lib/tinby/client.rb, line 78
def build_tinder_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
facebook_authentication_token() click to toggle source
# File lib/tinby/client.rb, line 86
def facebook_authentication_token
  TinderAuthFetcher.fetch_token(email, password)
end
login?() click to toggle source
# File lib/tinby/client.rb, line 66
def login?
  logined
end
sign_in() click to toggle source
# File lib/tinby/client.rb, line 60
def sign_in
  connection.token_auth(tinder_authentication_token)
  connection.headers['X-Auth-Token'] = tinder_authentication_token
  logined = true
end
tinder_authentication_token() click to toggle source
# File lib/tinby/client.rb, line 70
def tinder_authentication_token
  @tinder_authentication_token ||= JSON.parse(auth_request)['token']
end