Class: Tinderbot::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
11
# File 'lib/tinderbot/client.rb', line 8

def initialize(options = {})
  @logs_enabled = options[:logs_enabled]
  build_connection
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



6
7
8
# File 'lib/tinderbot/client.rb', line 6

def connection
  @connection
end

#logs_enabledObject

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

#profileObject



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


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



17
18
19
20
# File 'lib/tinderbot/client.rb', line 17

def (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

#updatesObject



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