betterific 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +15 -0
- data/lib/betterific/client_constants.rb +2 -0
- data/lib/betterific/json_client.rb +29 -0
- data/lib/betterific/protobuf_client.rb +29 -0
- data/lib/betterific/version.rb +1 -1
- data/spec/spec_helper.rb +66 -13
- metadata +13 -23
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODc5NGU1YjY0OTM2ZmM3NjViYzk1ZjNjM2YyN2E1OWE5ODM2ZDZlMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDljN2Y0MTU3MjIzMzllMDhkMjlhMTJhNjg3MWE3NTg5ZDJhNDM0OA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjIzZjJiOTFkODZmMDkyODkzMzc3ZWM4ZWVkODBlODhmOTA0Mjk2YWRjOWI0
|
10
|
+
Yjg2YTkyNTI2NTczMzQ4NmNlZTJmMWI4OWUxYmNkZTc0NDc3N2ZmZTdjNTQz
|
11
|
+
NWNkMWNlNTVmMTM1NzI0ZTlhZWZjOTIwZTJiNDI0YWQwZGYxYmM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YzIwNjUyNDJlNWZiYmFhODBkODRlYzFjODAzZDg4MmE1N2ZiMzk5ZDFhZGUy
|
14
|
+
YzM5MjA3ZDVjZTQyODAzMTg3OWIzNzhkYjc5YmIzZGZkMjg4YmYwZDNjZTdj
|
15
|
+
MDdkYzRlOTAyMmFhZjk4ZTBmNzE0MWZiMTQyNDUyNTEwOTA1ZWM=
|
data/README.md
CHANGED
@@ -55,6 +55,21 @@ you can use
|
|
55
55
|
|
56
56
|
Betterific::Client.betterifs(:ids => [id0, id1, ...])
|
57
57
|
|
58
|
+
### Comments
|
59
|
+
|
60
|
+
You can see a list of comments by id or by betterif\_id using
|
61
|
+
|
62
|
+
Betterific::Client.comments(:ids => [id0, id1, ...])
|
63
|
+
|
64
|
+
and
|
65
|
+
|
66
|
+
Betterific::Client.comments(:betterif_ids => [id0, id1, ...])
|
67
|
+
|
68
|
+
If using betterif\_ids, you may also specify the desired sort order, which can
|
69
|
+
be either least\_recent or most\_recent
|
70
|
+
|
71
|
+
Betterific::Client.comments(:betterif_ids => [id0, id1, ...], :order => 'least_recent')
|
72
|
+
|
58
73
|
### Tags and Users
|
59
74
|
|
60
75
|
You can see a list of tags or users by id using
|
@@ -5,6 +5,8 @@ module Betterific
|
|
5
5
|
|
6
6
|
# The base URL to GET betterifs.
|
7
7
|
BETTERIFS_BASE_URL = "#{BASE_URL}/betterifs".freeze
|
8
|
+
# The base URL to GET comments.
|
9
|
+
COMMENTS_BASE_URL = "#{BASE_URL}/comments".freeze
|
8
10
|
# The base URL to GET tags.
|
9
11
|
TAGS_BASE_URL = "#{BASE_URL}/tags".freeze
|
10
12
|
# The base URL to GET users.
|
@@ -39,6 +39,35 @@ module Betterific
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
# Get a list of comments.
|
43
|
+
#
|
44
|
+
# ==== Parameters
|
45
|
+
#
|
46
|
+
# * +opts+ - {:ids => [id0, id1, ..., idx]} specifies the ids of the
|
47
|
+
# comment(s) to return.
|
48
|
+
# * +opts+ - {:betterif_ids => [id0, id1, ..., idx]} specifies the ids of
|
49
|
+
# the betterif(s) for which to return comments. This is ignored if :ids
|
50
|
+
# is given.
|
51
|
+
# * +opts+ - {:order => (least_recent|most_recent)} fetches either the
|
52
|
+
# least recent or most recent comments. This is ignored unless
|
53
|
+
# :betterif_ids is given.
|
54
|
+
def self.comments(opts={})
|
55
|
+
if opts[:ids].nil? && opts[:betterif_ids].nil?
|
56
|
+
raise "No ids or betterif_ids given."
|
57
|
+
end
|
58
|
+
unless opts[:order].nil?
|
59
|
+
unless %w{least_recent most_recent}.include?(opts[:order])
|
60
|
+
raise "Invalid order given."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
params = [
|
64
|
+
opts[:ids] ? "comments[ids]=#{Array(opts[:ids]).map(&:to_s).join(',')}" : nil,
|
65
|
+
opts[:betterif_ids] ? "betterifs[ids]=#{Array(opts[:betterif_ids]).map(&:to_s).join(',')}" : nil,
|
66
|
+
opts[:order] ? "order=#{opts[:order]}" : nil
|
67
|
+
].compact
|
68
|
+
get_json("#{COMMENTS_BASE_URL}?#{params.join('&')}")
|
69
|
+
end
|
70
|
+
|
42
71
|
# Get a list of tags.
|
43
72
|
#
|
44
73
|
# ==== Parameters
|
@@ -107,6 +107,35 @@ module Betterific
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
+
# Get a list of comments.
|
111
|
+
#
|
112
|
+
# ==== Parameters
|
113
|
+
#
|
114
|
+
# * +opts+ - {:ids => [id0, id1, ..., idx]} specifies the ids of the
|
115
|
+
# comment(s) to return.
|
116
|
+
# * +opts+ - {:betterif_ids => [id0, id1, ..., idx]} specifies the ids of
|
117
|
+
# the betterif(s) for which to return comments. This is ignored if :ids
|
118
|
+
# is given.
|
119
|
+
# * +opts+ - {:order => (least_recent|most_recent)} fetches either the
|
120
|
+
# least recent or most recent comments. This is ignored unless
|
121
|
+
# :betterif_ids is given.
|
122
|
+
def self.comments(opts={})
|
123
|
+
if opts[:ids].nil? && opts[:betterif_ids].nil?
|
124
|
+
raise "No ids or betterif_ids given."
|
125
|
+
end
|
126
|
+
unless opts[:order].nil?
|
127
|
+
unless %w{least_recent most_recent}.include?(opts[:order])
|
128
|
+
raise "Invalid order given."
|
129
|
+
end
|
130
|
+
end
|
131
|
+
params = [
|
132
|
+
opts[:ids] ? "comments[ids]=#{Array(opts[:ids]).map(&:to_s).join(',')}" : nil,
|
133
|
+
opts[:betterif_ids] ? "betterifs[ids]=#{Array(opts[:betterif_ids]).map(&:to_s).join(',')}" : nil,
|
134
|
+
opts[:order] ? "order=#{opts[:order]}" : nil
|
135
|
+
].compact
|
136
|
+
get_protobuf("#{COMMENTS_BASE_URL}?#{params.join('&')}")
|
137
|
+
end
|
138
|
+
|
110
139
|
# Get a list of tags.
|
111
140
|
#
|
112
141
|
# ==== Parameters
|
data/lib/betterific/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'betterific'
|
2
|
+
require 'time'
|
2
3
|
|
4
|
+
BETTERIFIC_COMMENT_ID = 121 #:nodoc
|
3
5
|
BETTERIFIC_TAG_ID = 400937 #:nodoc
|
4
6
|
BETTERIF_ID = 224 #:nodoc
|
5
7
|
USER_ID = 2 #:nodoc
|
@@ -7,10 +9,12 @@ USER_ID = 2 #:nodoc
|
|
7
9
|
SEARCH_KINDS = %w{betterifs tags users}.freeze #:nodoc
|
8
10
|
|
9
11
|
def ensure_valid_api_response(resp, client_modjule, opts={})
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
unless opts[:comments]
|
13
|
+
if opts[:big]
|
14
|
+
resp.total_results.should > 10
|
15
|
+
else
|
16
|
+
resp.total_results.should >= (opts[:allow_empty] ? 0 : 1)
|
17
|
+
end
|
14
18
|
end
|
15
19
|
if opts[:big]
|
16
20
|
resp.num_results.should == 10
|
@@ -28,7 +32,7 @@ def ensure_valid_api_response(resp, client_modjule, opts={})
|
|
28
32
|
resp.betterifs.first.tags.is_a?(Array).should == true
|
29
33
|
elsif client_modjule == Betterific::ProtobufClient
|
30
34
|
resp.betterifs.first.tags.is_a?(ProtocolBuffers::RepeatedField).should == true
|
31
|
-
|
35
|
+
elsif client_modjule != Betterific::Client
|
32
36
|
raise "Invalid client_modjule #{client_modjule}"
|
33
37
|
end
|
34
38
|
if resp.betterifs.first.tags.size > 0
|
@@ -41,6 +45,23 @@ def ensure_valid_api_response(resp, client_modjule, opts={})
|
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
48
|
+
if opts[:comments]
|
49
|
+
if opts[:big]
|
50
|
+
resp.comments.size.should == 10
|
51
|
+
else
|
52
|
+
resp.comments.size.should >= (opts[:allow_empty] ? 0 : 1)
|
53
|
+
end
|
54
|
+
if client_modjule == Betterific::JsonClient
|
55
|
+
resp.comments.is_a?(Array).should == true
|
56
|
+
elsif client_modjule == Betterific::ProtobufClient
|
57
|
+
resp.comments.is_a?(ProtocolBuffers::RepeatedField).should == true
|
58
|
+
elsif client_modjule != Betterific::Client
|
59
|
+
raise "Invalid client_modjule #{client_modjule}"
|
60
|
+
end
|
61
|
+
if client_modjule == Betterific::ProtobufClient && resp.comments.size > 0
|
62
|
+
resp.comments.first.is_a?(BetterIf::Comment).should == true
|
63
|
+
end
|
64
|
+
end
|
44
65
|
if opts[:tags]
|
45
66
|
if opts[:big]
|
46
67
|
resp.tags.size.should == 10
|
@@ -51,7 +72,7 @@ def ensure_valid_api_response(resp, client_modjule, opts={})
|
|
51
72
|
resp.tags.is_a?(Array).should == true
|
52
73
|
elsif client_modjule == Betterific::ProtobufClient
|
53
74
|
resp.tags.is_a?(ProtocolBuffers::RepeatedField).should == true
|
54
|
-
|
75
|
+
elsif client_modjule != Betterific::Client
|
55
76
|
raise "Invalid client_modjule #{client_modjule}"
|
56
77
|
end
|
57
78
|
if client_modjule == Betterific::ProtobufClient && resp.tags.size > 0
|
@@ -68,7 +89,7 @@ def ensure_valid_api_response(resp, client_modjule, opts={})
|
|
68
89
|
resp.users.is_a?(Array).should == true
|
69
90
|
elsif client_modjule == Betterific::ProtobufClient
|
70
91
|
resp.users.is_a?(ProtocolBuffers::RepeatedField).should == true
|
71
|
-
|
92
|
+
elsif client_modjule != Betterific::Client
|
72
93
|
raise "Invalid client_modjule #{client_modjule}"
|
73
94
|
end
|
74
95
|
if client_modjule == Betterific::ProtobufClient && resp.users.size > 0
|
@@ -85,26 +106,58 @@ def client_test(modjule)
|
|
85
106
|
[:most_popular, :most_recent].each do |filter|
|
86
107
|
it "should load #{filter} betterifs" do
|
87
108
|
resp = modjule.betterifs(page_params.merge(:filter => filter))
|
88
|
-
ensure_valid_api_response(resp, :betterifs => true, :big => page_params.empty?)
|
109
|
+
ensure_valid_api_response(resp, modjule, :betterifs => true, :big => page_params.empty?)
|
89
110
|
end
|
90
111
|
end
|
91
112
|
it "should load betterifs via ids" do
|
92
113
|
resp = modjule.betterifs(page_params.merge(:ids => BETTERIF_ID))
|
93
|
-
ensure_valid_api_response(resp, :betterifs => true, :allow_empty => !page_params.empty?)
|
114
|
+
ensure_valid_api_response(resp, modjule, :betterifs => true, :allow_empty => !page_params.empty?)
|
94
115
|
if page_params.empty?
|
95
116
|
resp.betterifs.first.id.should == BETTERIF_ID
|
96
117
|
end
|
97
118
|
end
|
119
|
+
it "should load comments via ids" do
|
120
|
+
resp = modjule.comments(page_params.merge(:ids => BETTERIFIC_COMMENT_ID))
|
121
|
+
ensure_valid_api_response(resp, modjule, :comments => true, :allow_empty => !page_params.empty?)
|
122
|
+
if page_params.empty?
|
123
|
+
resp.comments.first.id.should == BETTERIFIC_COMMENT_ID
|
124
|
+
end
|
125
|
+
end
|
126
|
+
it "should load comments via betterif_ids" do
|
127
|
+
resp = modjule.comments(page_params.merge(:betterif_ids => BETTERIF_ID))
|
128
|
+
ensure_valid_api_response(resp, modjule, :comments => true, :allow_empty => !page_params.empty?)
|
129
|
+
if page_params.empty?
|
130
|
+
resp.comments.first.betterif.id.should == BETTERIF_ID
|
131
|
+
end
|
132
|
+
end
|
133
|
+
%w{least_recent most_recent}.each do |order|
|
134
|
+
it "should load comments via betterif_ids and #{order}" do
|
135
|
+
resp = modjule.comments(page_params.merge(:betterif_ids => BETTERIF_ID, :order => order))
|
136
|
+
ensure_valid_api_response(resp, modjule, :comments => true, :allow_empty => !page_params.empty?)
|
137
|
+
if page_params.empty?
|
138
|
+
resp.comments.first.betterif.id.should == BETTERIF_ID
|
139
|
+
if resp.comments.size > 1
|
140
|
+
first_comment_created_at = Time.parse(resp.comments.first.created_at)
|
141
|
+
last_comment_created_at = Time.parse(resp.comments.last.created_at)
|
142
|
+
if order == 'least_recent'
|
143
|
+
first_comment_created_at.should < last_comment_created_at
|
144
|
+
else
|
145
|
+
first_comment_created_at.should > last_comment_created_at
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
98
151
|
it "should load tags via ids" do
|
99
152
|
resp = modjule.tags(page_params.merge(:ids => BETTERIFIC_TAG_ID))
|
100
|
-
ensure_valid_api_response(resp, :tags => true, :allow_empty => !page_params.empty?)
|
153
|
+
ensure_valid_api_response(resp, modjule, :tags => true, :allow_empty => !page_params.empty?)
|
101
154
|
if page_params.empty?
|
102
155
|
resp.tags.first.id.should == BETTERIFIC_TAG_ID
|
103
156
|
end
|
104
157
|
end
|
105
158
|
it "should load users via ids" do
|
106
159
|
resp = modjule.users(page_params.merge(:ids => USER_ID))
|
107
|
-
ensure_valid_api_response(resp, :users => true, :allow_empty => !page_params.empty?)
|
160
|
+
ensure_valid_api_response(resp, modjule, :users => true, :allow_empty => !page_params.empty?)
|
108
161
|
if page_params.empty?
|
109
162
|
resp.users.first.id.should == USER_ID
|
110
163
|
end
|
@@ -115,7 +168,7 @@ def client_test(modjule)
|
|
115
168
|
q = [random_query, random_query].join(' ')
|
116
169
|
resp = modjule.search(page_params.merge(:namespace => kind, :q => q))
|
117
170
|
resp.q.should == q
|
118
|
-
ensure_valid_api_response(resp.send(kind), kind.to_sym => true, :allow_empty => true)
|
171
|
+
ensure_valid_api_response(resp.send(kind), modjule, kind.to_sym => true, :allow_empty => true)
|
119
172
|
if modjule == Betterific::JsonClient
|
120
173
|
SEARCH_KINDS.each do |other_kind|
|
121
174
|
next if kind == other_kind
|
@@ -129,7 +182,7 @@ def client_test(modjule)
|
|
129
182
|
resp = modjule.search(page_params.merge(:namespace => :all, :q => q))
|
130
183
|
resp.q.should == q
|
131
184
|
SEARCH_KINDS.each do |kind|
|
132
|
-
ensure_valid_api_response(resp.send(kind), kind.to_sym => true, :allow_empty => true)
|
185
|
+
ensure_valid_api_response(resp.send(kind), modjule, kind.to_sym => true, :allow_empty => true)
|
133
186
|
end
|
134
187
|
end
|
135
188
|
end
|
metadata
CHANGED
@@ -1,80 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: betterific
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brad Cater
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-04 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name: hashie
|
16
14
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
15
|
requirements:
|
19
16
|
- - ~>
|
20
17
|
- !ruby/object:Gem::Version
|
21
18
|
version: 2.0.5
|
22
|
-
|
19
|
+
name: hashie
|
23
20
|
type: :runtime
|
24
21
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
22
|
requirements:
|
27
23
|
- - ~>
|
28
24
|
- !ruby/object:Gem::Version
|
29
25
|
version: 2.0.5
|
26
|
+
prerelease: false
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name: json
|
32
28
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
29
|
requirements:
|
35
30
|
- - ~>
|
36
31
|
- !ruby/object:Gem::Version
|
37
32
|
version: 1.8.0
|
38
|
-
|
33
|
+
name: json
|
39
34
|
type: :runtime
|
40
35
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
36
|
requirements:
|
43
37
|
- - ~>
|
44
38
|
- !ruby/object:Gem::Version
|
45
39
|
version: 1.8.0
|
40
|
+
prerelease: false
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
name: ruby-protocol-buffers
|
48
42
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
43
|
requirements:
|
51
44
|
- - ~>
|
52
45
|
- !ruby/object:Gem::Version
|
53
46
|
version: 1.4.0
|
54
|
-
|
47
|
+
name: ruby-protocol-buffers
|
55
48
|
type: :development
|
56
49
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
50
|
requirements:
|
59
51
|
- - ~>
|
60
52
|
- !ruby/object:Gem::Version
|
61
53
|
version: 1.4.0
|
54
|
+
prerelease: false
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
|
-
name: rspec
|
64
56
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
57
|
requirements:
|
67
58
|
- - ~>
|
68
59
|
- !ruby/object:Gem::Version
|
69
60
|
version: 2.13.0
|
70
|
-
|
61
|
+
name: rspec
|
71
62
|
type: :development
|
72
63
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
64
|
requirements:
|
75
65
|
- - ~>
|
76
66
|
- !ruby/object:Gem::Version
|
77
67
|
version: 2.13.0
|
68
|
+
prerelease: false
|
78
69
|
description: This gem is a Ruby interface to the Betterific API.
|
79
70
|
email:
|
80
71
|
- bradcater@gmail.com
|
@@ -103,27 +94,26 @@ files:
|
|
103
94
|
- spec/spec_helper.rb
|
104
95
|
homepage: https://github.com/bradcater/betterific
|
105
96
|
licenses: []
|
97
|
+
metadata: {}
|
106
98
|
post_install_message:
|
107
99
|
rdoc_options: []
|
108
100
|
require_paths:
|
109
101
|
- lib
|
110
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
103
|
requirements:
|
113
104
|
- - ! '>='
|
114
105
|
- !ruby/object:Gem::Version
|
115
106
|
version: '0'
|
116
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
108
|
requirements:
|
119
109
|
- - ! '>='
|
120
110
|
- !ruby/object:Gem::Version
|
121
111
|
version: '0'
|
122
112
|
requirements: []
|
123
113
|
rubyforge_project:
|
124
|
-
rubygems_version:
|
114
|
+
rubygems_version: 2.0.5
|
125
115
|
signing_key:
|
126
|
-
specification_version:
|
116
|
+
specification_version: 4
|
127
117
|
summary: This gem is a Ruby interface to the Betterific API. It provides support via
|
128
118
|
Protocol Buffers if the ruby-protocol-buffers gem is installed; otherwise, it uses
|
129
119
|
JSON.
|