Class: Tinder::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/tinder/like.rb,
lib/tinder/pass.rb,
lib/tinder/client.rb,
lib/tinder/profile.rb,
lib/tinder/get_updates.rb,
lib/tinder/account_settings.rb,
lib/tinder/get_recommendations.rb

Constant Summary collapse

BASE_URI =

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

'https://api.gotinder.com'
ENDPOINTS =
{
  request_code:    "/v2/auth/sms/send?auth_type=sms",
  login:           "/v2/auth/login/sms",
  validate:        "/v2/auth/sms/validate?auth_type=sms",
  recommendations: "/v2/recs/core",
  updates:         "/updates"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_tokenObject

Returns the value of attribute api_token.



19
20
21
# File 'lib/tinder/client.rb', line 19

def api_token
  @api_token
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



20
21
22
# File 'lib/tinder/client.rb', line 20

def refresh_token
  @refresh_token
end

Instance Method Details

#account_settingsObject

Returns AccountSettings.

Returns:

  • AccountSettings



8
9
10
11
12
13
14
# File 'lib/tinder/account_settings.rb', line 8

def 
  response = get("https://api.gotinder.com/v2/meta")

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

  AccountSettings.new(response['data'])
end

#endpoint(action) ⇒ Object



64
65
66
# File 'lib/tinder/client.rb', line 64

def endpoint(action)
  "#{BASE_URI}#{ENDPOINTS[action]}"
end

#get(url, **data) ⇒ Object



27
28
29
30
31
# 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(&block) ⇒ Object Also known as: recommendations



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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

#get_updates(since: Time.now) ⇒ Object Also known as: updates

This includes the matches, as well as the messages, so must be parsed

Returns:

  • Updates a Dry::Struct object based on a JSON response



6
7
8
9
10
11
12
13
14
15
# 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

#like(person_id) ⇒ Object

This includes the matches, as well as the messages, so must be parsed

Returns:

  • Boolean true on success



8
9
10
11
12
13
14
15
# 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) ⇒ Object

Returns String The API key.

Parameters:

  • phone_number

    String Your phone number

  • confirmation_code

    String The code sent to your phone

Returns:

  • String The API key



54
55
56
57
58
59
60
61
62
# File 'lib/tinder/client.rb', line 54

def (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) ⇒ Object

This includes the matches, as well as the messages, so must be parsed

Returns:

  • Boolean true on success



8
9
10
11
12
13
14
15
# 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) ⇒ Object



22
23
24
25
# 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

#profileObject

Returns ActiveProfile.

Returns:

  • ActiveProfile



8
9
10
11
12
13
14
15
16
17
18
19
20
# 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

#request_code(phone_number) ⇒ Object

Parameters:

  • phone_number

    String



34
35
36
37
# 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

#validate(phone_number, confirmation_code) ⇒ Object

Returns String Named ‘refresh token’, this is one part of the 2-part authentication keys.

Parameters:

  • phone_number

    String Your phone number

  • confirmation_code

    String The code sent to your phone

Returns:

  • String Named ‘refresh token’, this is one part of the 2-part authentication keys



42
43
44
45
46
47
48
49
# 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