lonely_coder 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -0
- data/lib/lonely_coder/profile.rb +12 -0
- data/lib/lonely_coder/search.rb +31 -15
- data/lib/lonely_coder.rb +1 -1
- data/lonely_coder.gemspec +1 -1
- data/spec/cassettes/load_profile_from_search.yml +1284 -723
- data/spec/cassettes/paginate_search_results_by_10.yml +1410 -791
- data/spec/cassettes/paginate_search_results_by_10_with_failure.yml +1502 -0
- data/spec/cassettes/search_by_filters.yml +1315 -733
- data/spec/cassettes/search_finding_no_results.yml +1365 -0
- data/spec/pagination_spec.rb +44 -12
- data/spec/profile_spec.rb +23 -10
- data/spec/search_spec.rb +13 -2
- metadata +7 -2
data/CHANGELOG
ADDED
data/lib/lonely_coder/profile.rb
CHANGED
@@ -95,5 +95,17 @@ class OKCupid
|
|
95
95
|
def ==(other)
|
96
96
|
self.username == other.username
|
97
97
|
end
|
98
|
+
|
99
|
+
def eql?(other)
|
100
|
+
self.username == other.username
|
101
|
+
end
|
102
|
+
|
103
|
+
def hash
|
104
|
+
if self.username
|
105
|
+
self.username.hash
|
106
|
+
else
|
107
|
+
super
|
108
|
+
end
|
109
|
+
end
|
98
110
|
end
|
99
111
|
end
|
data/lib/lonely_coder/search.rb
CHANGED
@@ -32,12 +32,12 @@ class OKCupid
|
|
32
32
|
|
33
33
|
options.each do |name,value|
|
34
34
|
self.send("add_#{name}_option", value)
|
35
|
-
# if OKCupid.const_defined?("#{name.to_s.camelize}Filter")
|
36
|
-
# @filters << OKCupid.const_get("#{name.to_s.camelize}Filter").new(name, value)
|
37
|
-
# else
|
38
|
-
# @filters << Filter.new(name, value)
|
39
|
-
# end
|
40
35
|
end
|
36
|
+
|
37
|
+
# OKC needs an initial time key of 1 to represent "waaaay in the past"
|
38
|
+
# futures searches will use the OKC server value returned from the first
|
39
|
+
# results set
|
40
|
+
@timekey = 1
|
41
41
|
end
|
42
42
|
|
43
43
|
def add_order_by_option(value)
|
@@ -121,15 +121,18 @@ class OKCupid
|
|
121
121
|
def results
|
122
122
|
return @results if @results
|
123
123
|
|
124
|
-
|
125
|
-
|
124
|
+
# the first results request has to receive a full HTML page.
|
125
|
+
# subseqent calls can make json requests
|
126
|
+
page = @browser.get(url)
|
127
|
+
@timekey = page.search('script')[0].text.match(/CurrentGMT = new Date\(([\d]+)\*[\d]+\)/).captures[0]
|
126
128
|
|
127
|
-
|
129
|
+
# OKCupid will return previous profiles if there aren't enough
|
130
|
+
# profiles to fill a query, so we stop that with a set.
|
131
|
+
@results = Set.new
|
132
|
+
@results += page.search('.match_row').collect do |node|
|
128
133
|
OKCupid::Profile.from_search_result(node)
|
129
134
|
end
|
130
|
-
|
131
|
-
@browser.pluggable_parser.html = Mechanize::Page
|
132
|
-
|
135
|
+
|
133
136
|
@results
|
134
137
|
end
|
135
138
|
|
@@ -142,16 +145,29 @@ class OKCupid
|
|
142
145
|
# mygender=m
|
143
146
|
# no idea what the following parameters do, but without them, the search
|
144
147
|
# behaves erratically
|
145
|
-
# &timekey=1
|
146
148
|
# &custom_search=0
|
149
|
+
#
|
150
|
+
# OKCupid timestamps searches for pagniation. The first search gets a timestamp
|
151
|
+
# of 1 (e.g. 1 second into the epoch) and future searches are stamped with
|
152
|
+
# some server cache value. If that server value isn't submitted, the results
|
153
|
+
# for pagniation don't quite match what you'd expect: you'll get duplicates,
|
154
|
+
# or lower numbers than expected.
|
155
|
+
# &timekey=1
|
156
|
+
|
147
157
|
def magic_params_not_truly_understood
|
148
|
-
"timekey
|
158
|
+
"timekey=#{@timekey}&custom_search=0"
|
149
159
|
end
|
150
160
|
|
161
|
+
# returns true if it worked, false if not.
|
162
|
+
# OKCupid searches will return duplicate results if you attempt to
|
163
|
+
# page beyond the availble results.
|
151
164
|
def load_next_page
|
152
165
|
@browser.pluggable_parser.html = SearchPaginationParser
|
153
166
|
|
154
|
-
|
167
|
+
@pagination.next
|
168
|
+
previous_length = @results.size
|
169
|
+
|
170
|
+
page = @browser.get(ajax_url)
|
155
171
|
|
156
172
|
@results += page.search('.match_row').collect do |node|
|
157
173
|
OKCupid::Profile.from_search_result(node)
|
@@ -159,7 +175,7 @@ class OKCupid
|
|
159
175
|
|
160
176
|
@browser.pluggable_parser.html = Mechanize::Page
|
161
177
|
|
162
|
-
|
178
|
+
previous_length != @results.size
|
163
179
|
end
|
164
180
|
|
165
181
|
def url
|
data/lib/lonely_coder.rb
CHANGED
data/lonely_coder.gemspec
CHANGED