Class: OKCupid

Inherits:
Object
  • Object
show all
Defined in:
lib/lonely_coder.rb,
lib/lonely_coder/search.rb,
lib/lonely_coder/mailbox.rb,
lib/lonely_coder/profile.rb,
lib/lonely_coder/authentication.rb,
lib/lonely_coder/search/options/age.rb,
lib/lonely_coder/search/options/filter.rb,
lib/lonely_coder/search/options/radius.rb,
lib/lonely_coder/search/magic_constants.rb,
lib/lonely_coder/search/options/location.rb,
lib/lonely_coder/search/options/order_by.rb,
lib/lonely_coder/search/options/ethnicity.rb,
lib/lonely_coder/search/options/paginator.rb,
lib/lonely_coder/search/options/require_photo.rb,
lib/lonely_coder/search/search_pagination_parser.rb

Defined Under Namespace

Modules: MagicNumbers Classes: AgeFilter, Authentication, AuthenticationParser, EthnicityFilter, Filter, LocationParameter, Mailbox, OrderByParameter, Paginator, Profile, RadiusFilter, RequirePhotoFilter, Search, SearchPaginationParser

Constant Summary collapse

BaseUrl =
'http://www.okcupid.com'
VERSION =
'0.1.5'
WhiteSpace =
"\302\240"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username = nil, password = nil) ⇒ OKCupid

Returns a new instance of OKCupid.



16
17
18
19
20
# File 'lib/lonely_coder.rb', line 16

def initialize(username=nil, password=nil)
  @browser = Mechanize.new 
  @browser.user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11'
  authenticate(username, password)
end

Class Method Details

.strip(str) ⇒ Object



23
24
25
# File 'lib/lonely_coder.rb', line 23

def self.strip(str)
  str.gsub(WhiteSpace, ' ').strip
end

Instance Method Details

#authenticate(username, password) ⇒ Object



5
6
7
# File 'lib/lonely_coder/authentication.rb', line 5

def authenticate(username, password)
  @authentication = Authentication.new(username, password, @browser)
end

#conversation_for(id) ⇒ Object



8
9
10
# File 'lib/lonely_coder/mailbox.rb', line 8

def conversation_for(id)
  Mailbox::Conversation.by_id(id, @browser)
end

#love(n = 20) ⇒ Object



27
28
29
# File 'lib/lonely_coder.rb', line 27

def love(n=20)
  '' * n
end

#mailboxObject



4
5
6
# File 'lib/lonely_coder/mailbox.rb', line 4

def mailbox
  @mailbox ||= Mailbox.new(@browser)
end

#profile_for(username) ⇒ Object



4
5
6
# File 'lib/lonely_coder/profile.rb', line 4

def profile_for(username)
  Profile.by_username(username, @browser)
end

#search(options = {}) ⇒ Search

Creates a new Search with the passed options to act as query parameters. A search will not trigger a query to OKCupid until ‘results` is called.

Parameters:

  • options (Hash) (defaults to: {})

    a list of options for the search

Options Hash (options):

  • :min_age (Integer) — default: 18

    Minimum age to search for.

  • :max_age (Integer) — default: 99

    Maximum age to search for.

  • :gentation (String)

    Gentation is OKCupid’s portmanteau for ‘gender and orientation’. Acceptable values are: “girls who like guys”, “guys who like girls”, “girls who like girls”, “guys who like guys”, “both who like bi guys”, “both who like bi girls”, “straight girls only”, “straight guys only”, “gay girls only”, “gay guys only”, “bi girls only”, “bi guys only”, “everybody” this option is required.

  • :order_by (String) — default: 'match %'

    The sort order of the search results. Acceptable values are ‘match %’,‘friend %’, ‘enemy %’, ‘special blend’, ‘join’, and ‘last login’.

  • :radius (Integer) — default: 25

    The search radius, in miles. Acceptable values are 25, 50, 100, 250, 500. You must also specific a :location option.

  • :location (Integer, String) — default: 'near me'

    . A specific search location. Acceptable values are ‘near me’, ‘anywhere’, a “City, State” pair (e.g. ‘Chicago, Illinois’) or OKCupid location id which can be obtained with Search#location_id_for(“City, State”). If specifiying a location other than ‘near me’ or ‘anywhere’ you may also provide a :radius option

  • :require_photo (true, false) — default: true

    . Search for profiles that have photos

  • :relationship_status (String) — default: 'single'

    . Acceptable values are ‘single’, ‘not single’, ‘any’

Returns:

  • (Search)

    A Search without results loaded. To trigger a query against OKCupid call ‘results`



49
50
51
# File 'lib/lonely_coder/search.rb', line 49

def search(options={})
  Search.new(options, @browser)
end