lonely_coder 0.1.0

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.
@@ -0,0 +1,8 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe "helpers" do
5
+ it "OKCupid.strip removs funky lead and trailing white space" do
6
+ OKCupid.strip(" Today – 2:40am ").should == "Today – 2:40am"
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe "snagging a location id" do
4
+ it "takes a query and returns an id" do
5
+ VCR.use_cassette('find_location') do
6
+ @loc_id = OKCupid::Search.location_id_for('Ann Arbor, MI')
7
+ end
8
+
9
+ @loc_id.should == '4305734'
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe "pagination" do
4
+ before(:each) do
5
+ VCR.use_cassette('paginate_search_results', :erb => {:username => ENV['OKC_USERNAME'], :password => ENV['OKC_PASSWORD']}) do
6
+ @search = OKCupid.new(ENV['OKC_USERNAME'], ENV['OKC_PASSWORD']).search({
7
+ gentation: 'girls who like guys'
8
+ })
9
+ @search.results
10
+ @search.load_next_page
11
+ end
12
+ end
13
+
14
+ it "snags 10 more results" do
15
+ @search.results.size.should == 20
16
+ @search.results.all? {|p| p.kind_of?(OKCupid::Profile)}.should == true
17
+ end
18
+ end
@@ -0,0 +1,175 @@
1
+ #encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe "Profile" do
5
+ it "checks for equality based on username" do
6
+ OKCupid::Profile.new(:username => 'someguy', :age => 22).should == OKCupid::Profile.new(:username => 'someguy', :age => 35)
7
+ end
8
+ end
9
+
10
+ describe "Profile from specific find" do
11
+ before(:each) do
12
+ VCR.use_cassette('search_by_username', :erb => {:username => ENV['OKC_USERNAME'], :password => ENV['OKC_PASSWORD']}) do
13
+ @profile = OKCupid.new(ENV['OKC_USERNAME'], ENV['OKC_PASSWORD']).profile_for('voliobi_te')
14
+ end
15
+ end
16
+
17
+ it "has a username" do
18
+ @profile.username.should == 'voliobi_te'
19
+ end
20
+
21
+ it "has an age" do
22
+ @profile.age.should == '21'
23
+ end
24
+
25
+ it "has a match %" do
26
+ @profile.match.should == 45
27
+ end
28
+
29
+ it "has a friend %" do
30
+ @profile.friend.should == 56
31
+ end
32
+
33
+ it "has an enemy %" do
34
+ @profile.enemy.should == 33
35
+ end
36
+
37
+ it "has a location" do
38
+ @profile.location.should == 'Ann Arbor, Michigan'
39
+ end
40
+
41
+ it " doesn't has a small avatar url" do
42
+ @profile.small_avatar_url.should == nil
43
+ end
44
+
45
+ it "has a collection of thumbnail urls" do
46
+ @profile.profile_thumb_urls.should == ["http://akcdn.okccdn.com/media/img/user/d_160.png"]
47
+ end
48
+
49
+ it "has a sex" do
50
+ @profile.sex.should == 'M'
51
+ end
52
+
53
+ it "has an orientation" do
54
+ @profile.orientation.should == 'Gay'
55
+ end
56
+
57
+ it "has a signle status" do
58
+ @profile.single.should == 'Single'
59
+ end
60
+
61
+ it "has a last_online" do
62
+ @profile.last_online.should == "Today – 2:40am"
63
+ end
64
+
65
+ it "has a ethnicity" do
66
+ @profile.ethnicity.should == 'White'
67
+ end
68
+
69
+ it "has a height" do
70
+ @profile.height.should == '6′ 2″ (1.88m).'
71
+ end
72
+
73
+ it "has a body_type" do
74
+ @profile.body_type.should == 'Thin'
75
+ end
76
+
77
+ it "has a diet" do
78
+ @profile.diet.should == 'Mostly anything'
79
+ end
80
+
81
+ it "has a smokes" do
82
+ @profile.smokes.should == 'No'
83
+ end
84
+
85
+ it "has a drinks" do
86
+ @profile.drinks.should == 'Socially'
87
+ end
88
+
89
+ it "has a drugs" do
90
+ @profile.drugs.should == 'Never'
91
+ end
92
+
93
+ it "has a religion" do
94
+ @profile.religion.should == 'Agnosticism but not too serious about it'
95
+ end
96
+
97
+ it "has a sign" do
98
+ @profile.sign.should == 'Gemini and it’s fun to think about'
99
+ end
100
+
101
+ it "has a education" do
102
+ @profile.education.should == 'Working on college/university'
103
+ end
104
+
105
+ it "has a job" do
106
+ @profile.job.should == 'Student'
107
+ end
108
+
109
+ it "has a income" do
110
+ @profile.income.should == nil
111
+ end
112
+
113
+ it "has a offspring" do
114
+ @profile.offspring.should == nil
115
+ end
116
+
117
+ it "has a pets" do
118
+ @profile.pets.should == nil
119
+ end
120
+
121
+ it "has a speaks" do
122
+ @profile.speaks.should == 'English (Fluently), Serbian (Fluently), Croatian (Fluently)'
123
+ end
124
+
125
+ end
126
+
127
+ describe "Profile from search result" do
128
+ before(:each) do
129
+ VCR.use_cassette('search_by_filters', :erb => {:username => ENV['OKC_USERNAME'], :password => ENV['OKC_PASSWORD']}) do
130
+ @profile = OKCupid.new(ENV['OKC_USERNAME'], ENV['OKC_PASSWORD']).search({
131
+ gentation: 'girls who like guys'
132
+ }).results.first
133
+ end
134
+ end
135
+
136
+ it "has a username" do
137
+ @profile.username.should == 'a2girl77'
138
+ end
139
+
140
+ it "has an age" do
141
+ @profile.age.should == '34'
142
+ end
143
+
144
+ it "has a match %" do
145
+ @profile.match.should == 92
146
+ end
147
+
148
+ it "has a friend %" do
149
+ @profile.friend.should == 82
150
+ end
151
+
152
+ it "has an enemy %" do
153
+ @profile.enemy.should == 0
154
+ end
155
+
156
+ it "has a location" do
157
+ @profile.location.should == 'Ann Arbor, Michigan'
158
+ end
159
+
160
+ it "has a small avatar url" do
161
+ @profile.small_avatar_url.should == 'http://ak0.okccdn.com/php/load_okc_image.php/images/82x82/82x82/126x67/497x439/2/5607892676107173868.jpeg'
162
+ end
163
+
164
+ it "has a sex" do
165
+ @profile.sex.should == 'F'
166
+ end
167
+
168
+ it "has an orientation" do
169
+ @profile.orientation.should == 'Straight'
170
+ end
171
+
172
+ it "has a signle status" do
173
+ @profile.single.should == 'Single'
174
+ end
175
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Search" do
4
+
5
+ it "complains about missing required keys" do
6
+ lambda { OKCupid::Search.new({}) }.should raise_error(OKCupid::Search::FilterError)
7
+ end
8
+
9
+ it "complains about malformed key values" do
10
+ lambda { OKCupid::Search.new({
11
+ :gentation => 'Cats who like laser beams',
12
+ }) }.should raise_error(OKCupid::Filter::BadValue)
13
+ end
14
+
15
+ describe "generating the url" do
16
+ it "combines all the filters into a params string" do
17
+ OKCupid::Search.new({
18
+ :min_age => 33,
19
+ :max_age => 34,
20
+ :order_by => 'Match %',
21
+ :last_login => 'last decade',
22
+ :gentation => 'Guys who like guys',
23
+ :location => 'near me', # can be 'near me', 'anywhere', a location name (e.g. 'Ann Arbor, MI'), or a location id
24
+ :radius => 25, # acceptable values are 25, 50, 100, 250, 500
25
+ :require_photo => false,
26
+ :relationship_status => 'any'
27
+ }).url.should =='/match?matchOrderBy=MATCH&filter2=5,315360000&locid=0&filter4=3,25&filter5=1,0&filter6=35,0&filter7=0,20&filter8=2,33,34'
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "Results" do
33
+ it "returns an array of OKCupid::Profile objects" do
34
+ VCR.use_cassette('search_by_filters', :erb => {:username => ENV['OKC_USERNAME'], :password => ENV['OKC_PASSWORD']}) do
35
+ @results = OKCupid.new(ENV['OKC_USERNAME'], ENV['OKC_PASSWORD']).search({
36
+ gentation: 'girls who like guys'
37
+ }).results
38
+ end
39
+
40
+ @results.should be_kind_of(Array)
41
+ @results.size.should == 10
42
+ @results.all? {|p| p.kind_of?(OKCupid::Profile)}.should == true
43
+ end
44
+ end
45
+
46
+ describe "Filters" do
47
+ describe "lookup" do
48
+ it "finds the encoded value" do
49
+ OKCupid::Filter.new('relationship_status', 'single').lookup('single').should == 2
50
+ end
51
+ end
52
+
53
+ describe "parameterization" do
54
+ it "strings itself" do
55
+ OKCupid::Filter.new('relationship_status', 'single').to_param(1).should == 'filter1=35,2'
56
+ end
57
+
58
+ it "custom filters: ethnicity are added together" do
59
+ OKCupid::EthnicityFilter.new('ethnicity', ['white', 'black']).to_param(1).should == 'filter1=9,264'
60
+ end
61
+
62
+ it "custom filters: order_by" do
63
+ OKCupid::OrderByFilter.new('order_by', 'Match %').to_param(1).should == 'matchOrderBy=MATCH'
64
+ end
65
+
66
+ it "custom filters: age" do
67
+ OKCupid::AgeFilter.new('age', [18,22]).to_param(1).should == 'filter1=2,18,22'
68
+ end
69
+
70
+ it "custom filters: radius" do
71
+ OKCupid::RadiusFilter.new('radius', 50).to_param(1).should == 'filter1=3,50'
72
+ end
73
+
74
+ it "custom filters: radius" do
75
+ OKCupid::RadiusFilter.new('radius', nil).to_param(1).should == nil
76
+ end
77
+
78
+ describe "custom filters: require photo" do
79
+ it "with true" do
80
+ OKCupid::RequirePhotoFilter.new('require_photo', true).to_param(1).should == 'filter1=1,1'
81
+ end
82
+
83
+ it "with false" do
84
+ OKCupid::RequirePhotoFilter.new('require_photo', false).to_param(1).should == 'filter1=1,0'
85
+ end
86
+ end
87
+
88
+ describe 'custom filters: location' do
89
+ it "can use the 'near me' value" do
90
+ OKCupid::LocationFilter.new('location', 'Near me').to_param(1).should == 'locid=0'
91
+ end
92
+
93
+ it 'can use a location query' do
94
+ OKCupid::LocationFilter.new('location', 'Cincinnati, Ohio').to_param(1).should == 'lquery=Cincinnati,%20Ohio'
95
+ end
96
+
97
+ it "can use a location_id" do
98
+ OKCupid::LocationFilter.new('location', 4335338).to_param(1).should == 'locid=4335338'
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: UTF-8
2
+ require 'bundler'
3
+ Bundler.require(:default, :test)
4
+ require 'lonely_coder'
5
+
6
+ VCR.configure do |c|
7
+ c.cassette_library_dir = 'spec/cassettes'
8
+ c.hook_into :webmock
9
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lonely_coder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Trek Glowacki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.2.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.2.1
46
+ description: ''
47
+ email:
48
+ - trek.glowacki@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - README.mdown
56
+ - lib/lonely_coder.rb
57
+ - lib/lonely_coder/authentication.rb
58
+ - lib/lonely_coder/magic_constants.rb
59
+ - lib/lonely_coder/profile.rb
60
+ - lib/lonely_coder/search.rb
61
+ - lib/lonely_coder/search_pagination_parser.rb
62
+ - spec/authentication_spec.rb
63
+ - spec/cassettes/failed_authentication.yml
64
+ - spec/cassettes/find_location.yml
65
+ - spec/cassettes/paginate_search_results.yml
66
+ - spec/cassettes/search_by_filters.yml
67
+ - spec/cassettes/search_by_username.yml
68
+ - spec/cassettes/successful_authentication.yml
69
+ - spec/helper_spec.rb
70
+ - spec/location_id_spec.rb
71
+ - spec/pagination_spec.rb
72
+ - spec/profile_spec.rb
73
+ - spec/search_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: http://github.com/trek/lonely_coder
76
+ licenses: []
77
+ post_install_message: ! "\n \n \n \n ,d88b.d88b,\n 88888888888\n `Y8888888Y'\n
78
+ \ `Y888Y'\n `Y'\n \n Good luck out there.\n \n \n "
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 1.8.21
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: ''
100
+ test_files:
101
+ - spec/authentication_spec.rb
102
+ - spec/cassettes/failed_authentication.yml
103
+ - spec/cassettes/find_location.yml
104
+ - spec/cassettes/paginate_search_results.yml
105
+ - spec/cassettes/search_by_filters.yml
106
+ - spec/cassettes/search_by_username.yml
107
+ - spec/cassettes/successful_authentication.yml
108
+ - spec/helper_spec.rb
109
+ - spec/location_id_spec.rb
110
+ - spec/pagination_spec.rb
111
+ - spec/profile_spec.rb
112
+ - spec/search_spec.rb
113
+ - spec/spec_helper.rb