CSApi 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +5 -18
- data/csapi.gemspec +1 -0
- data/examples/example.rb +40 -22
- data/lib/csapi.rb +71 -5
- data/lib/csapi/version.rb +1 -1
- data/readme.md +14 -16
- metadata +31 -22
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 37402553ba84503cfbe5ee0b2548551865a9b765
|
4
|
+
data.tar.gz: 285cad08bf766155b0acefd66bdb3110a5b0e562
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28a155a0b139bd9536ce28251928e04d059bea187e34e0a88bfc1a1c776b370e49b8b32b3020ef18dad4454a2040e250686a708796bac92ed5401160f52b72dc
|
7
|
+
data.tar.gz: 6402789e62c0237709a7512a25c9d43bb642f7de80b415ad849f84dcad136c8eab5bb63bc16181eed7237058c73c4c62c43d4dd395061b8750e6f24323e4f325
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,9 @@
|
|
1
|
-
|
1
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004
|
2
2
|
|
3
|
-
|
3
|
+
(C) 2012 Roberto Hidalgo un@rob.mx, Those listed at CONTRIBUTORS
|
4
4
|
|
5
|
-
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
5
|
+
Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
|
12
6
|
|
13
|
-
|
14
|
-
included in all copies or substantial portions of the Software.
|
7
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
15
8
|
|
16
|
-
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
9
|
+
You just DO WHAT THE FUCK YOU WANT TO.
|
data/csapi.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.description = "Simple wrapper of couchsurfing.org API for accessing profile, friends, searching, etc."
|
12
12
|
gem.summary = "I have no idea what is this"
|
13
13
|
gem.homepage = "https://github.com/unRob/CouchSurfing-API"
|
14
|
+
gem.licenses = ['WTFPL', 'GPLv2']
|
14
15
|
gem.has_rdoc = false
|
15
16
|
|
16
17
|
gem.files = `git ls-files`.split($/)
|
data/examples/example.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#encoding: utf-8
|
3
3
|
|
4
|
-
|
4
|
+
require './lib/CSApi.rb'
|
5
|
+
require 'pp'
|
5
6
|
|
6
7
|
begin
|
7
8
|
api = CS::Api.new('username','password')
|
@@ -15,28 +16,45 @@ end
|
|
15
16
|
# ===
|
16
17
|
profile = api.profile('205974')
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
|
20
|
+
## ===
|
21
|
+
## Get a user's photos, by default ours
|
22
|
+
## ===
|
22
23
|
photos = api.photos('205974')
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
## ===
|
26
|
+
## Get a user's friends, by default ours
|
27
|
+
## ===
|
27
28
|
friends = api.friends('205974')
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
## ===
|
31
|
+
## Get a user's references, by default ours
|
32
|
+
## ===
|
32
33
|
references = api.references('205974')
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
## ===
|
36
|
+
## Get the current user's recent requests
|
37
|
+
## ===
|
37
38
|
limit = 10
|
38
39
|
requests = api.requests(limit)
|
39
40
|
|
41
|
+
# ===
|
42
|
+
# Get the current user's inbox messages
|
43
|
+
# ===
|
44
|
+
m = api.messages('inbox', 1)
|
45
|
+
pp m.count
|
46
|
+
|
47
|
+
m.each do |m|
|
48
|
+
pp m
|
49
|
+
end
|
50
|
+
|
51
|
+
if m.has_more?
|
52
|
+
pp m.more.count
|
53
|
+
else
|
54
|
+
pp "end of messages"
|
55
|
+
end
|
56
|
+
|
57
|
+
|
40
58
|
# ===
|
41
59
|
# Create a new Couch Request
|
42
60
|
# ===
|
@@ -53,13 +71,13 @@ details = {
|
|
53
71
|
}
|
54
72
|
couch_request = CS::Request.new(details)
|
55
73
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
74
|
+
api.requests(1).each do |key, value|
|
75
|
+
pp value
|
76
|
+
end
|
77
|
+
#
|
78
|
+
## ===
|
79
|
+
## Search for people in a city with various search constraints
|
80
|
+
## ===
|
63
81
|
options = {
|
64
82
|
location: 'venice',
|
65
83
|
gender: 'female',
|
@@ -74,4 +92,4 @@ options = {
|
|
74
92
|
results = api.search(options)
|
75
93
|
results.each do |id, user|
|
76
94
|
puts "Found (UID:#{id}) #{user[:name]} in #{user[:location]} with a couch status of #{user[:status]} and a photo #{user[:pic]}\n\n"
|
77
|
-
end
|
95
|
+
end
|
data/lib/csapi.rb
CHANGED
@@ -26,10 +26,8 @@ module CS
|
|
26
26
|
raise CS::AuthError.new("Could not login") if r.code != 200
|
27
27
|
|
28
28
|
@cookies = []
|
29
|
-
r.headers['Set-Cookie'].split(
|
30
|
-
|
31
|
-
@cookies = "#{key}=#{value}"
|
32
|
-
end
|
29
|
+
@cookies=r.headers['Set-Cookie'].split(/;/).first
|
30
|
+
#end
|
33
31
|
|
34
32
|
data = JSON.parse r.body
|
35
33
|
@uid = data['url'].gsub(/[^\d]/, '')
|
@@ -64,6 +62,33 @@ module CS
|
|
64
62
|
r = self.class.get(url)
|
65
63
|
JSON.parse r.body
|
66
64
|
end
|
65
|
+
|
66
|
+
|
67
|
+
def messages(type='inbox', limit=5, start=nil)
|
68
|
+
|
69
|
+
types = ['inbox', 'sent'];
|
70
|
+
throw ArgumentError.new("Can't fetch messages of kind #{type}") if !types.include? type;
|
71
|
+
|
72
|
+
url = "/users/#{@uid}/messages"
|
73
|
+
q = {
|
74
|
+
type: type,
|
75
|
+
limit: limit
|
76
|
+
}
|
77
|
+
|
78
|
+
if (start)
|
79
|
+
q[:start] = start
|
80
|
+
end
|
81
|
+
|
82
|
+
r = self.class.get(url, query:q);
|
83
|
+
object = JSON.parse r.body
|
84
|
+
|
85
|
+
return CS::Messages.new(object, q, self);
|
86
|
+
end
|
87
|
+
|
88
|
+
def message(url)
|
89
|
+
r = self.class.get(url)
|
90
|
+
JSON.parse r.body
|
91
|
+
end
|
67
92
|
|
68
93
|
def userdata
|
69
94
|
@profile
|
@@ -140,6 +165,47 @@ module CS
|
|
140
165
|
class APIError < StandardError
|
141
166
|
end
|
142
167
|
|
168
|
+
class Messages
|
169
|
+
|
170
|
+
@after = nil
|
171
|
+
@q = {}
|
172
|
+
@data = []
|
173
|
+
|
174
|
+
def initialize(object, q, ref)
|
175
|
+
|
176
|
+
@after = object['after'] if object.include? 'after';
|
177
|
+
@q = q;
|
178
|
+
@ref = ref
|
179
|
+
@data = object['object']
|
180
|
+
end
|
181
|
+
|
182
|
+
def count
|
183
|
+
return @data.count
|
184
|
+
end
|
185
|
+
|
186
|
+
def has_more?
|
187
|
+
return @after != nil
|
188
|
+
end
|
189
|
+
|
190
|
+
def each
|
191
|
+
@data.each do |url|
|
192
|
+
yield @ref.message(url)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def more
|
197
|
+
more = @ref.messages(@q[:type], @q[:limit], @after)
|
198
|
+
@data = more['object']
|
199
|
+
@after = more.include?('after') ? more['after'] : nil;
|
200
|
+
return self
|
201
|
+
end
|
202
|
+
|
203
|
+
private
|
204
|
+
@ref = nil
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
|
143
209
|
class Request
|
144
210
|
@api = nil
|
145
211
|
|
@@ -177,4 +243,4 @@ module CS
|
|
177
243
|
end
|
178
244
|
end
|
179
245
|
|
180
|
-
end
|
246
|
+
end
|
data/lib/csapi/version.rb
CHANGED
data/readme.md
CHANGED
@@ -37,22 +37,20 @@ Or by hand:
|
|
37
37
|
## Contributors
|
38
38
|
|
39
39
|
* [Peter Nosko](https://github.com/pnosko) - Search
|
40
|
+
* [Davit-gh](https://github.com/davit-gh) - Messages
|
40
41
|
|
41
42
|
|
42
43
|
##License
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
57
|
-
|
58
|
-
Redistributions of files must retain the above copyright notice.
|
44
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
45
|
+
Version 2, December 2004
|
46
|
+
|
47
|
+
(C) 2012 Roberto Hidalgo <un@rob.mx>, Those listed at CONTRIBUTORS
|
48
|
+
|
49
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
50
|
+
copies of this license document, and changing it is allowed as long
|
51
|
+
as the name is changed.
|
52
|
+
|
53
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
54
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
55
|
+
|
56
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
metadata
CHANGED
@@ -1,49 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: CSApi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Roberto Hidalgo
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-04-16 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: httparty
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: json
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: nokogiri
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - '>='
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
type: :runtime
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
description: Simple wrapper of couchsurfing.org API for accessing profile, friends,
|
48
56
|
searching, etc.
|
49
57
|
email:
|
@@ -62,27 +70,28 @@ files:
|
|
62
70
|
- lib/csapi/version.rb
|
63
71
|
- readme.md
|
64
72
|
homepage: https://github.com/unRob/CouchSurfing-API
|
65
|
-
licenses:
|
73
|
+
licenses:
|
74
|
+
- WTFPL
|
75
|
+
- GPLv2
|
76
|
+
metadata: {}
|
66
77
|
post_install_message:
|
67
78
|
rdoc_options: []
|
68
79
|
require_paths:
|
69
80
|
- lib
|
70
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
82
|
requirements:
|
73
|
-
- -
|
83
|
+
- - '>='
|
74
84
|
- !ruby/object:Gem::Version
|
75
85
|
version: '0'
|
76
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
87
|
requirements:
|
79
|
-
- -
|
88
|
+
- - '>='
|
80
89
|
- !ruby/object:Gem::Version
|
81
90
|
version: '0'
|
82
91
|
requirements: []
|
83
92
|
rubyforge_project:
|
84
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.0.3
|
85
94
|
signing_key:
|
86
|
-
specification_version:
|
95
|
+
specification_version: 4
|
87
96
|
summary: I have no idea what is this
|
88
97
|
test_files: []
|