class Tindy::Client
Constants
- GENDER_OPTIONS
- REPORT_OPTIONS
- TINDER_APP_ID
Public Class Methods
new(fb_token)
click to toggle source
# File lib/tindy/client.rb, line 20 def initialize(fb_token) @fb_token = fb_token @tinder_token = nil end
Public Instance Methods
authenticate!()
click to toggle source
# File lib/tindy/client.rb, line 25 def authenticate! return if authenticated? auth_obj = { facebook_token: @fb_token, facebook_id: TINDER_APP_ID }.to_json res = self.class.post("/auth", headers: headers, body: auth_obj) raise "Failed to authenticate. Response body: #{res.body}" if res.code != 200 @tinder_token = JSON.parse(res.body)["token"] end
like(id)
click to toggle source
# File lib/tindy/client.rb, line 40 def like(id) post("/like/#{id}") end
pass(id)
click to toggle source
# File lib/tindy/client.rb, line 44 def pass(id) post("/pass/#{id}") end
recommendations()
click to toggle source
# File lib/tindy/client.rb, line 52 def recommendations post("/recs") end
report_user(id, cause)
click to toggle source
# File lib/tindy/client.rb, line 56 def report_user(id, cause) raise "Incorrect cause provided (:spam, :offensive/:inappropriate)" unless REPORT_OPTIONS.key?(cause) post("/report/#{id}", { cause: REPORT_OPTIONS[cause] }) end
send_message(id, message)
click to toggle source
# File lib/tindy/client.rb, line 62 def send_message(id, message) post("/matches/#{id}", { message: message }) end
update_distance(distance)
click to toggle source
# File lib/tindy/client.rb, line 82 def update_distance(distance) update_profile(distance_filter: distance) end
update_gender(gender)
click to toggle source
# File lib/tindy/client.rb, line 70 def update_gender(gender) update_profile(gender: gender) end
update_location(latitude, longitude)
click to toggle source
# File lib/tindy/client.rb, line 66 def update_location(latitude, longitude) post("/user/ping", { lat: latitude, lon: longitude }) end
update_max_age(age)
click to toggle source
# File lib/tindy/client.rb, line 78 def update_max_age(age) update_profile(age_filter_max: age) end
update_min_age(age)
click to toggle source
# File lib/tindy/client.rb, line 74 def update_min_age(age) update_profile(age_filter_min: age) end
update_profile(options = {})
click to toggle source
# File lib/tindy/client.rb, line 86 def update_profile(options = {}) gender_option = options[:gender] validate_gender!(gender_option) options.merge!(gender: GENDER_OPTIONS[gender_option]) if gender_option.is_a?(Symbol) post("/profile", options) end
updates()
click to toggle source
# File lib/tindy/client.rb, line 48 def updates post("/updates", { last_activity_date: "" }) end
Private Instance Methods
authenticated?()
click to toggle source
# File lib/tindy/client.rb, line 97 def authenticated? !!@tinder_token end
headers()
click to toggle source
# File lib/tindy/client.rb, line 114 def headers { "content-type" => "application/json", "User-agent" => "Tinder/4.0.9 (iPhone; iOS 8.1.1; Scale/2.00)", "platform" => "ios" }.tap { |h| h["X-Auth-Token"] = @tinder_token if authenticated? } end
post(path, body)
click to toggle source
# File lib/tindy/client.rb, line 108 def post(path, body) raise "Not authenticated!" unless authenticated? self.class.post(path, headers: headers, body: body.to_json).parsed_response end
validate_gender!(gender)
click to toggle source
# File lib/tindy/client.rb, line 101 def validate_gender!(gender) return if gender.nil? return if (GENDER_OPTIONS.keys + GENDER_OPTIONS.values).include?(gender) raise "Invalid argument passed for gender (:male, :female, 0, 1) '#{gender}'" end