class Tinder::Client

Constants

BASE_URI

Always prefer V2 endpoints as the API is less buggy than V1

ENDPOINTS

Attributes

api_token[RW]
refresh_token[RW]

Public Instance Methods

account_settings() click to toggle source

@return AccountSettings

# File lib/tinder/account_settings.rb, line 8
def account_settings
  response = get("https://api.gotinder.com/v2/meta")

  fail('Unexpected response') if response.dig('data').nil?

  AccountSettings.new(response['data'])
end
endpoint(action) click to toggle source
# File lib/tinder/client.rb, line 64
def endpoint(action)
  "#{BASE_URI}#{ENDPOINTS[action]}"
end
get(url, **data) click to toggle source
# File lib/tinder/client.rb, line 27
def get(url, **data)
  # GET requests won't get a response using JSON
  response = Faraday.get(url, data, headers)
  JSON.parse(response.body) unless response.body.nil?
end
get_recommendations() { |get_recommendations && return| ... } click to toggle source
# File lib/tinder/get_recommendations.rb, line 4
def get_recommendations(&block)
  if block_given?
    yield get_recommendations && return
  end

  data = get(endpoint(:recommendations))

  fail 'Connection Timeout' unless data.dig('data', 'timeout').nil?

  error_message = data.dig('error', 'message')
  fail 'Rate Limited' if error_message == 'RATE_LIMITED'
  return [] if error_message == 'There is no one around you'
  fail 'Unknown Error' unless error_message.nil?

  results = Array(data.dig('data', 'results'))
  return [] if results.first.is_a?(String) && results.first == 'You are out of likes today. Come back later to continue swiping on more people.'

  results.map { |user_data| Recommendation.new(user_data) }
end
Also aliased as: recommendations
get_updates(since: Time.now) click to toggle source

This includes the matches, as well as the messages, so must be parsed @return Updates a Dry::Struct object based on a JSON response

# File lib/tinder/get_updates.rb, line 6
def get_updates(since: Time.now)
  response = post(endpoint(:updates))

  fail 'Connection Timeout' unless response.dig('data', 'timeout').nil?
  fail 'Rate Limited' if response.dig('error', 'message') == 'RATE_LIMITED'
  # The next one only occurs without Tinder Plus subscription
  fail 'No Results Left' if response.dig('error', 'message') == 'There is no one around you'

  updates = Updates.new(response['data'])
end
Also aliased as: updates
like(person_id) click to toggle source

This includes the matches, as well as the messages, so must be parsed @return Boolean true on success

# File lib/tinder/like.rb, line 8
def like(person_id)
  response = get("https://api.gotinder.com/user/like/#{person_id}")

  fail 'Connection Timeout' unless response.dig('data', 'timeout').nil?
  fail 'Rate Limited' if response.dig('error', 'message') == 'RATE_LIMITED'

  true
end
login(phone_number, refresh_token) click to toggle source

@param phone_number String Your phone number @param confirmation_code String The code sent to your phone @return String The API key

# File lib/tinder/client.rb, line 54
def login(phone_number, refresh_token)
  data     = { refresh_token: refresh_token, phone_number: phone_number }
  response = post(endpoint(:login), data)

  @api_token   = response.dig('data', 'api_token') || fail(UnexpectedResponse(response))
  @id          = response['data']['_id']
  @is_new_user = response['data']['is_new_user']
  @api_token
end
pass(person_id) click to toggle source

This includes the matches, as well as the messages, so must be parsed @return Boolean true on success

# File lib/tinder/pass.rb, line 8
def pass(person_id)
  response = get("https://api.gotinder.com/user/pass/#{person_id}")

  fail 'Connection Timeout' unless response.dig('data', 'timeout').nil?
  fail 'Rate Limited' if response.dig('error', 'message') == 'RATE_LIMITED'

  true
end
post(url, **data) click to toggle source
# File lib/tinder/client.rb, line 22
def post(url, **data)
  response = Faraday.post(url, JSON.generate(data), headers)
  JSON.parse(response.body) unless response.body.nil?
end
profile() click to toggle source

@return ActiveProfile

# File lib/tinder/profile.rb, line 8
def profile

  data = { include: "account,boost,email_settings,instagram," \
                    "likes,notifications,plus_control,products," \
                    "purchase,spotify,super_likes,tinder_u,"\
                    "travel,tutorials,user" }

  response = get("https://api.gotinder.com/v2/profile", data)

  fail('Unexpected response') if response.dig('data').nil?

  ActiveProfile.new(response['data'])
end
recommendations(&block)
Alias for: get_recommendations
request_code(phone_number) click to toggle source

@param phone_number String

# File lib/tinder/client.rb, line 34
def request_code(phone_number)
  response = post(endpoint(:request_code), phone_number: phone_number)
  response.dig('data', 'sms_sent') || fail(UnexpectedResponse(response))
end
updates(since: Time.now)
Alias for: get_updates
validate(phone_number, confirmation_code) click to toggle source

@param phone_number String Your phone number @param confirmation_code String The code sent to your phone @return String Named 'refresh token', this is one part of the 2-part authentication keys

# File lib/tinder/client.rb, line 42
def validate(phone_number, confirmation_code)
  data = { otp_code:     confirmation_code,
           phone_number: phone_number,
           is_update:    false }

  response       = post(endpoint(:validate), data)
  @refresh_token = response.dig('data', 'refresh_token') || fail(UnexpectedResponse(response))
end

Protected Instance Methods

headers() click to toggle source
# File lib/tinder/client.rb, line 70
def headers
  {
    "app_version":  "6.9.4",
    "platform":     "ios",
    "content-type": "application/json",
    "User-agent":   "Tinder/7.5.3 (iPhone; iOS 10.3.2; Scale/2.00)",
    "Accept":       "application/json",
    "X-Auth-Token": api_token
  }
end