urtak 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/Rakefile +7 -0
- data/lib/urtak/version.rb +3 -0
- data/lib/urtak.rb +279 -0
- data/spec/base.rb +26 -0
- data/spec/client_spec.rb +293 -0
- data/urtak.gemspec +28 -0
- metadata +122 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/lib/urtak.rb
ADDED
@@ -0,0 +1,279 @@
|
|
1
|
+
require 'urtak/version'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'digest/sha1'
|
4
|
+
|
5
|
+
# XML is supported by the API, but this wrapper does not parse it automatically!
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
module Urtak
|
9
|
+
module Errors
|
10
|
+
class Unimplemented < StandardError ; end
|
11
|
+
class NoToken < StandardError ; end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Api
|
15
|
+
attr_accessor :options
|
16
|
+
|
17
|
+
def initialize(user_options = {})
|
18
|
+
@options = {
|
19
|
+
:api_key => nil,
|
20
|
+
:publication_key => nil,
|
21
|
+
:email => nil,
|
22
|
+
:user_id => nil,
|
23
|
+
:api_base => "https://urtak.com/api",
|
24
|
+
:api_format => "JSON",
|
25
|
+
:client_name => "Urtak API Wrapper for Ruby, v#{Urtak::VERSION}"
|
26
|
+
}.merge(user_options.select{|k,v|!v.nil?})
|
27
|
+
end
|
28
|
+
|
29
|
+
# ACCOUNTS
|
30
|
+
def get_account(id)
|
31
|
+
Response.new(fire(:get, "accounts/#{id}"))
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_account(attributes)
|
35
|
+
Response.new(fire(:post, "accounts", {:account => attributes}))
|
36
|
+
end
|
37
|
+
|
38
|
+
# PUBLICATIONS
|
39
|
+
def get_publication(key = options[:publication_key])
|
40
|
+
Response.new(fire(:get, "publications/#{key}"))
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_publication(attributes)
|
44
|
+
Response.new(fire(:post, "publications", {:publication => attributes}))
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_publication(key, attributes)
|
48
|
+
Response.new(fire(:put, "publications/#{key}", {:publication => attributes}))
|
49
|
+
end
|
50
|
+
|
51
|
+
# URTAKS
|
52
|
+
def list_urtaks(options = {})
|
53
|
+
Response.new(fire(:get, "urtaks", options))
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_urtak(property, value, options = {})
|
57
|
+
if property == :id
|
58
|
+
path = "urtaks/#{value}"
|
59
|
+
elsif property == :post_id
|
60
|
+
path = "urtaks/post/#{value}"
|
61
|
+
elsif property == :permalink
|
62
|
+
path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}"
|
63
|
+
end
|
64
|
+
|
65
|
+
Response.new(fire(:get, path, options))
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_urtak(urtak_attributes, questions=[])
|
69
|
+
Response.new(fire(:post, 'urtaks', {:urtak => urtak_attributes.merge(:questions => questions)}))
|
70
|
+
end
|
71
|
+
|
72
|
+
def update_urtak(property, attributes)
|
73
|
+
value = attributes.delete(property)
|
74
|
+
|
75
|
+
if property == :id
|
76
|
+
path = "urtaks/#{value}"
|
77
|
+
elsif property == :post_id
|
78
|
+
path = "urtaks/post/#{value}"
|
79
|
+
elsif property == :permalink
|
80
|
+
path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}"
|
81
|
+
end
|
82
|
+
|
83
|
+
Response.new(fire(:put, path, {:urtak => attributes}))
|
84
|
+
end
|
85
|
+
|
86
|
+
# URTAK QUESTIONS
|
87
|
+
def list_urtak_questions(property, value, options = {})
|
88
|
+
if property == :id
|
89
|
+
path = "urtaks/#{value}/questions"
|
90
|
+
elsif property == :post_id
|
91
|
+
path = "urtaks/post/#{value}/questions"
|
92
|
+
elsif property == :permalink
|
93
|
+
path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions"
|
94
|
+
end
|
95
|
+
|
96
|
+
Response.new(fire(:get, path, options))
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_urtak_question(property, value, id, options = {})
|
100
|
+
if property == :id
|
101
|
+
path = "urtaks/#{value}/questions/#{id}"
|
102
|
+
elsif property == :post_id
|
103
|
+
path = "urtaks/post/#{value}/questions/#{id}"
|
104
|
+
elsif property == :permalink
|
105
|
+
path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions/#{id}"
|
106
|
+
end
|
107
|
+
|
108
|
+
Response.new(fire(:get, path, options))
|
109
|
+
end
|
110
|
+
|
111
|
+
def create_urtak_question(property, value, question)
|
112
|
+
if property == :id
|
113
|
+
path = "urtaks/#{value}/questions"
|
114
|
+
elsif property == :post_id
|
115
|
+
path = "urtaks/post/#{value}/questions"
|
116
|
+
elsif property == :permalink
|
117
|
+
path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions"
|
118
|
+
end
|
119
|
+
|
120
|
+
Response.new(fire(:post, path, {:question => question}))
|
121
|
+
end
|
122
|
+
|
123
|
+
def approve_urtak_question(property, value, id)
|
124
|
+
if property == :id
|
125
|
+
path = "urtaks/#{value}/questions/#{id}/approve"
|
126
|
+
elsif property == :post_id
|
127
|
+
path = "urtaks/post/#{value}/questions/#{id}/approve"
|
128
|
+
elsif property == :permalink
|
129
|
+
path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions/#{id}/approve"
|
130
|
+
end
|
131
|
+
|
132
|
+
Response.new(fire(:put, path))
|
133
|
+
end
|
134
|
+
|
135
|
+
def reject_urtak_question(property, value, id)
|
136
|
+
if property == :id
|
137
|
+
path = "urtaks/#{value}/questions/#{id}/reject"
|
138
|
+
elsif property == :post_id
|
139
|
+
path = "urtaks/post/#{value}/questions/#{id}/reject"
|
140
|
+
elsif property == :permalink
|
141
|
+
path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions/#{id}/reject"
|
142
|
+
end
|
143
|
+
|
144
|
+
Response.new(fire(:put, path))
|
145
|
+
end
|
146
|
+
|
147
|
+
def spam_urtak_question(property, value, id)
|
148
|
+
if property == :id
|
149
|
+
path = "urtaks/#{value}/questions/#{id}/spam"
|
150
|
+
elsif property == :post_id
|
151
|
+
path = "urtaks/post/#{value}/questions/#{id}/spam"
|
152
|
+
elsif property == :permalink
|
153
|
+
path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions/#{id}/spam"
|
154
|
+
end
|
155
|
+
|
156
|
+
Response.new(fire(:put, path))
|
157
|
+
end
|
158
|
+
|
159
|
+
def ham_urtak_question(property, value, id)
|
160
|
+
if property == :id
|
161
|
+
path = "urtaks/#{value}/questions/#{id}/ham"
|
162
|
+
elsif property == :post_id
|
163
|
+
path = "urtaks/post/#{value}/questions/#{id}/ham"
|
164
|
+
elsif property == :permalink
|
165
|
+
path = "urtaks/hash/#{Digest::SHA1.hexdigest(value)}/questions/#{id}/ham"
|
166
|
+
end
|
167
|
+
|
168
|
+
Response.new(fire(:put, path))
|
169
|
+
end
|
170
|
+
|
171
|
+
# QUESTIONS
|
172
|
+
def list_questions(options={})
|
173
|
+
Response.new(fire(:get, "questions", options))
|
174
|
+
end
|
175
|
+
|
176
|
+
def get_question(id)
|
177
|
+
Response.new(fire(:get, "questions/#{id}"))
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
private
|
182
|
+
def fire(method, path, data={})
|
183
|
+
if method == :get
|
184
|
+
RestClient.get("#{options[:api_base]}/#{path}",
|
185
|
+
"User-Agent" => options[:client_name],
|
186
|
+
:params => retrieve_token.merge(data).merge(create_signature),
|
187
|
+
:accept => create_accept){|response, request, result| response }
|
188
|
+
elsif method == :head
|
189
|
+
RestClient.head("#{options[:api_base]}/#{path}",
|
190
|
+
"User-Agent" => options[:client_name],
|
191
|
+
:params => retrieve_token.merge(data).merge(create_signature),
|
192
|
+
:accept => create_accept){|response, request, result| response }
|
193
|
+
elsif method == :post
|
194
|
+
RestClient.post("#{options[:api_base]}/#{path}",
|
195
|
+
JSON.generate(retrieve_token.merge(data).merge(create_signature)),
|
196
|
+
"User-Agent" => options[:client_name],
|
197
|
+
:accept => create_accept,
|
198
|
+
:content_type => :json){|response, request, result| response }
|
199
|
+
elsif method == :put
|
200
|
+
RestClient.put("#{options[:api_base]}/#{path}",
|
201
|
+
JSON.generate(retrieve_token.merge(data).merge(create_signature)),
|
202
|
+
"User-Agent" => options[:client_name],
|
203
|
+
:accept => create_accept,
|
204
|
+
:content_type => :json){|response, request, result| response }
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def retrieve_token
|
209
|
+
{
|
210
|
+
:publication_key => options[:publication_key],
|
211
|
+
:email => options[:email],
|
212
|
+
:user_id => options[:user_id]
|
213
|
+
}.select{|k,v|!v.nil?}
|
214
|
+
end
|
215
|
+
|
216
|
+
def create_signature
|
217
|
+
timestamp = Time.now.to_i
|
218
|
+
signature = Digest::SHA1.hexdigest("#{timestamp} #{options[:api_key]}")
|
219
|
+
{:timestamp => timestamp, :signature => signature}
|
220
|
+
end
|
221
|
+
|
222
|
+
def create_accept
|
223
|
+
if options[:api_format] == "JSON"
|
224
|
+
"application/vnd.urtak.urtak+json; version=1.0"
|
225
|
+
else
|
226
|
+
"application/vnd.urtak.urtak+xml; version=1.0"
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
class Response
|
232
|
+
attr_accessor :raw, :body
|
233
|
+
|
234
|
+
def initialize(response)
|
235
|
+
@raw = response
|
236
|
+
|
237
|
+
# TODO case statement
|
238
|
+
if response.headers[:content_type].nil?
|
239
|
+
@body = response
|
240
|
+
elsif response.headers[:content_type].match(/json/)
|
241
|
+
@body = JSON.parse(response)
|
242
|
+
elsif response.headers[:content_type].match(/xml/)
|
243
|
+
raise Urtak::Errors::Unimplemented
|
244
|
+
else
|
245
|
+
@body = response
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def code
|
250
|
+
raw.code
|
251
|
+
end
|
252
|
+
|
253
|
+
def error
|
254
|
+
response.body['error'] ? response.body['error']['message'] : nil
|
255
|
+
end
|
256
|
+
|
257
|
+
def headers
|
258
|
+
raw.headers
|
259
|
+
end
|
260
|
+
|
261
|
+
def success?
|
262
|
+
code >= 200 && code < 400
|
263
|
+
end
|
264
|
+
|
265
|
+
def failure?
|
266
|
+
code >= 400
|
267
|
+
end
|
268
|
+
|
269
|
+
def not_found?
|
270
|
+
code == 404
|
271
|
+
end
|
272
|
+
|
273
|
+
# naive
|
274
|
+
def found?
|
275
|
+
code == 200 || code == 304
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
279
|
+
end
|
data/spec/base.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
def is_ruby_19?
|
2
|
+
RUBY_VERSION == '1.9.1' or RUBY_VERSION == '1.9.2'
|
3
|
+
end
|
4
|
+
|
5
|
+
Encoding.default_internal = Encoding.default_external = "ASCII-8BIT" if is_ruby_19?
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rspec'
|
9
|
+
require 'vcr'
|
10
|
+
|
11
|
+
RSpec.configure do |c|
|
12
|
+
c.extend VCR::RSpec::Macros
|
13
|
+
end
|
14
|
+
|
15
|
+
VCR.config do |c|
|
16
|
+
c.cassette_library_dir = 'spec/fixtures'
|
17
|
+
c.stub_with :fakeweb
|
18
|
+
end
|
19
|
+
|
20
|
+
begin
|
21
|
+
require "ruby-debug"
|
22
|
+
rescue LoadError
|
23
|
+
# NOP, ignore
|
24
|
+
end
|
25
|
+
|
26
|
+
require File.dirname(__FILE__) + '/../lib/urtak'
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,293 @@
|
|
1
|
+
require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
|
2
|
+
|
3
|
+
describe Urtak::Api do
|
4
|
+
|
5
|
+
attr_accessor :settings
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
@settings = { :api_base => ENV['API_BASE'] }
|
9
|
+
end
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
@client = Urtak::Api.new(@settings)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should form http requests with proper accept headers"
|
16
|
+
it "should form http post requests with a proper content type"
|
17
|
+
it "should sign requests properly"
|
18
|
+
|
19
|
+
context "accounts" do
|
20
|
+
it "should create an account" do
|
21
|
+
VCR.use_cassette('create_account') do
|
22
|
+
response = @client.create_account({:email => "testuser+#{Time.now.to_i}@urtak.com"})
|
23
|
+
response.code.should eq(201)
|
24
|
+
settings[:user_id] = response.body['account']['id']
|
25
|
+
settings[:email] = response.body['account']['email']
|
26
|
+
settings[:api_key] = response.body['account']['api_key']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should find your account" do
|
31
|
+
VCR.use_cassette('get_account', :match_requests_on => [:method, :host, :path]) do
|
32
|
+
response = @client.get_account(settings[:user_id])
|
33
|
+
response.code.should eq(200)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "publications" do
|
39
|
+
it "should create a publication" do
|
40
|
+
VCR.use_cassette('create_publication') do
|
41
|
+
@client = Urtak::Api.new(@settings)
|
42
|
+
publication = {
|
43
|
+
:name => "Fun with VCRs",
|
44
|
+
:domains => "knossos.local"
|
45
|
+
}
|
46
|
+
response = @client.create_publication(publication)
|
47
|
+
response.code.should eq(201)
|
48
|
+
settings[:publication_key] = response.body['publication']['key']
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should find a publication" do
|
53
|
+
VCR.use_cassette('get_publication', :match_requests_on => [:method, :host, :path]) do
|
54
|
+
@client = Urtak::Api.new(@settings)
|
55
|
+
response = @client.get_publication(@settings[:publication_key])
|
56
|
+
response.class.should eq(Urtak::Response)
|
57
|
+
response.code.should eq(200)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should update a publication" do
|
62
|
+
VCR.use_cassette('update_publication') do
|
63
|
+
@client = Urtak::Api.new(@settings)
|
64
|
+
publication = {
|
65
|
+
:name => "Fun with VCRs",
|
66
|
+
:domains => "funwithvcrs.com"
|
67
|
+
}
|
68
|
+
response = @client.update_publication(@settings[:publication_key], publication)
|
69
|
+
response.code.should eq(204)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "urtaks" do
|
75
|
+
it "should create an urtak" do
|
76
|
+
VCR.use_cassette('create_urtak') do
|
77
|
+
@client = Urtak::Api.new(@settings)
|
78
|
+
@post_id = Digest::SHA1.hexdigest("#{Time.now.to_i}")
|
79
|
+
urtak = {
|
80
|
+
:title => "200 Fun Things to Do with Cassette Tape",
|
81
|
+
:post_id => @post_id,
|
82
|
+
:permalink => "http://knossos.local/#{@post_id}-200-fun-things-to-do-with-cassette-tape"
|
83
|
+
}
|
84
|
+
questions = [
|
85
|
+
{:text => "Do you know what betamax is?"},
|
86
|
+
{:text => "Are you familiar with physics behind magnetic storage?"},
|
87
|
+
{:text => "Have you ever had to repair a cassette tape?"},
|
88
|
+
{:text => "Have you ever pulled tape from a reel for fun?"}
|
89
|
+
]
|
90
|
+
response = @client.create_urtak(urtak, questions)
|
91
|
+
response.code.should eq(201)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should list urtaks" do
|
96
|
+
VCR.use_cassette('list_urtaks', :match_requests_on => [:method, :host, :path]) do
|
97
|
+
@client = Urtak::Api.new(@settings)
|
98
|
+
response = @client.list_urtaks
|
99
|
+
response.code.should eq(200)
|
100
|
+
response.body['urtaks']['urtak'].class.should eq(Array)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should find an urtak by id" do
|
105
|
+
VCR.use_cassette('list_urtaks', :match_requests_on => [:method, :host, :path]) do
|
106
|
+
@client = Urtak::Api.new(@settings)
|
107
|
+
response = @client.list_urtaks
|
108
|
+
@urtak = response.body['urtaks']['urtak'].last
|
109
|
+
|
110
|
+
VCR.use_cassette('get_urtak_by_id', :match_requests_on => [:method, :host, :path]) do
|
111
|
+
@client = Urtak::Api.new(@settings)
|
112
|
+
response = @client.get_urtak(:id, @urtak['id'])
|
113
|
+
response.code.should eq(200)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should find an urtak by permalink hash" do
|
119
|
+
VCR.use_cassette('list_urtaks', :match_requests_on => [:method, :host, :path]) do
|
120
|
+
@client = Urtak::Api.new(@settings)
|
121
|
+
response = @client.list_urtaks
|
122
|
+
@urtak = response.body['urtaks']['urtak'].last
|
123
|
+
|
124
|
+
VCR.use_cassette('get_urtak_by_permalink', :match_requests_on => [:method, :host, :path]) do
|
125
|
+
@client = Urtak::Api.new(@settings)
|
126
|
+
response = @client.get_urtak(:permalink, @urtak['permalink'])
|
127
|
+
response.code.should eq(200)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should find an urtak by post_id" do
|
133
|
+
VCR.use_cassette('list_urtaks', :match_requests_on => [:method, :host, :path]) do
|
134
|
+
@client = Urtak::Api.new(@settings)
|
135
|
+
response = @client.list_urtaks
|
136
|
+
@urtak = response.body['urtaks']['urtak'].last
|
137
|
+
|
138
|
+
VCR.use_cassette('get_urtak_by_post_id', :match_requests_on => [:method, :host, :path]) do
|
139
|
+
@client = Urtak::Api.new(@settings)
|
140
|
+
response = @client.get_urtak(:post_id, @urtak['post_id'])
|
141
|
+
response.code.should eq(200)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should update an urtak" do
|
147
|
+
VCR.use_cassette('list_urtaks', :match_requests_on => [:method, :host, :path]) do
|
148
|
+
@client = Urtak::Api.new(@settings)
|
149
|
+
response = @client.list_urtaks
|
150
|
+
@urtak = response.body['urtaks']['urtak'].last
|
151
|
+
|
152
|
+
VCR.use_cassette('update_urtak') do
|
153
|
+
@client = Urtak::Api.new(@settings)
|
154
|
+
|
155
|
+
urtak = {
|
156
|
+
:title => "200 really fun things to do with a cassette tape",
|
157
|
+
:post_id => @urtak['post_id'],
|
158
|
+
:permalink => "http://knossos.local/#{@urtak['post_id']}-200-fun-things-to-do-with-cassette-tape"
|
159
|
+
}
|
160
|
+
|
161
|
+
response = @client.update_urtak(:post_id, urtak)
|
162
|
+
response.code.should eq(204)
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "urtak-questions" do
|
170
|
+
before(:each) do
|
171
|
+
VCR.use_cassette('list_urtaks', :match_requests_on => [:method, :host, :path]) do
|
172
|
+
@client = Urtak::Api.new(@settings)
|
173
|
+
response = @client.list_urtaks
|
174
|
+
@urtak = response.body['urtaks']['urtak'].last
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should list questions on an urtak" do
|
179
|
+
VCR.use_cassette('list_urtak_questions', :match_requests_on => [:method, :host, :path]) do
|
180
|
+
response = @client.list_urtak_questions(:id, @urtak['id'])
|
181
|
+
response.code.should eq(200)
|
182
|
+
response.body['questions']['question'].class.should eq(Array)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should find a question on an urtak" do
|
187
|
+
VCR.use_cassette('list_urtak_questions', :match_requests_on => [:method, :host, :path]) do
|
188
|
+
response = @client.list_urtak_questions(:id, @urtak['id'])
|
189
|
+
@question = response.body['questions']['question'].last
|
190
|
+
|
191
|
+
VCR.use_cassette('find_urtak_question', :match_requests_on => [:method, :host, :path]) do
|
192
|
+
response = @client.get_urtak_question(:id, @urtak['id'], @question['id'])
|
193
|
+
response.code.should eq(200)
|
194
|
+
response.body['question'].class.should eq(Hash)
|
195
|
+
response.body['question']['status'].should eq("approved")
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should create a question" do
|
201
|
+
VCR.use_cassette('list_urtak_questions', :match_requests_on => [:method, :host, :path]) do
|
202
|
+
VCR.use_cassette('create_urtak_question') do
|
203
|
+
question = {:text => "Have you ever owned a VCR?"}
|
204
|
+
response = @client.create_urtak_question(:id, @urtak['id'], question)
|
205
|
+
response.code.should eq(201)
|
206
|
+
base = "#{@client.options[:api_base]}/urtaks/#{@urtak['id']}/questions"
|
207
|
+
response.headers[:location].should =~ /#{Regexp.escape(base)}\/\d+/
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should approve a question" do
|
213
|
+
VCR.use_cassette('list_urtak_questions', :match_requests_on => [:method, :host, :path]) do
|
214
|
+
response = @client.list_urtak_questions(:id, @urtak['id'])
|
215
|
+
@question = response.body['questions']['question'].last
|
216
|
+
|
217
|
+
VCR.use_cassette('approve_urtak_question') do
|
218
|
+
response = @client.approve_urtak_question(:id, @urtak['id'], @question['id'])
|
219
|
+
response.code.should eq(204)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should reject a question" do
|
225
|
+
VCR.use_cassette('list_urtak_questions', :match_requests_on => [:method, :host, :path]) do
|
226
|
+
response = @client.list_urtak_questions(:id, @urtak['id'])
|
227
|
+
@question = response.body['questions']['question'].last
|
228
|
+
|
229
|
+
VCR.use_cassette('reject_urtak_question') do
|
230
|
+
response = @client.reject_urtak_question(:id, @urtak['id'], @question['id'])
|
231
|
+
response.code.should eq(204)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should mark a question as spam" do
|
237
|
+
VCR.use_cassette('list_urtak_questions', :match_requests_on => [:method, :host, :path]) do
|
238
|
+
response = @client.list_urtak_questions(:id, @urtak['id'])
|
239
|
+
@question = response.body['questions']['question'].last
|
240
|
+
|
241
|
+
VCR.use_cassette('spam_urtak_question') do
|
242
|
+
response = @client.spam_urtak_question(:id, @urtak['id'], @question['id'])
|
243
|
+
response.code.should eq(204)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should mark a question as ham" do
|
249
|
+
VCR.use_cassette('list_urtak_questions', :match_requests_on => [:method, :host, :path]) do
|
250
|
+
response = @client.list_urtak_questions(:id, @urtak['id'])
|
251
|
+
@question = response.body['questions']['question'].last
|
252
|
+
|
253
|
+
VCR.use_cassette('ham_urtak_question') do
|
254
|
+
response = @client.ham_urtak_question(:id, @urtak['id'], @question['id'])
|
255
|
+
response.code.should eq(204)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
context "questions" do
|
262
|
+
it "should list questions" do
|
263
|
+
VCR.use_cassette('list_questions', :match_requests_on => [:method, :host, :path]) do
|
264
|
+
@client = Urtak::Api.new(@settings)
|
265
|
+
response = @client.list_questions
|
266
|
+
if ENV['ADMIN']
|
267
|
+
response.code.should eq(200)
|
268
|
+
else
|
269
|
+
response.code.should eq(403)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should find a question" do
|
275
|
+
VCR.use_cassette('list_questions', :match_requests_on => [:method, :host, :path]) do
|
276
|
+
@client = Urtak::Api.new(@settings)
|
277
|
+
|
278
|
+
VCR.use_cassette('get_question', :match_requests_on => [:method, :host, :path]) do
|
279
|
+
if ENV['ADMIN']
|
280
|
+
@question = @client.list_questions.body['questions']['question'].last
|
281
|
+
response = @client.get_question(@question['id'])
|
282
|
+
response.code.should eq(200)
|
283
|
+
else
|
284
|
+
# Shouldn't matter what the ID is here
|
285
|
+
response = @client.get_question(1)
|
286
|
+
response.code.should eq(403)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
end
|
data/urtak.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "urtak/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "urtak"
|
7
|
+
s.version = Urtak::VERSION
|
8
|
+
s.authors = ["Kunal Shah"]
|
9
|
+
s.email = ["kunal@urtak.com"]
|
10
|
+
s.homepage = "https://github.com/urtak/urtak-rb"
|
11
|
+
s.summary = %q{Ruby Client for the Urtak REST API}
|
12
|
+
s.description = %q{Ruby Client for the Urtak REST API}
|
13
|
+
|
14
|
+
s.rubyforge_project = "urtak"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
s.add_development_dependency "fakeweb"
|
25
|
+
s.add_development_dependency "vcr"
|
26
|
+
s.add_runtime_dependency "rest-client"
|
27
|
+
s.add_runtime_dependency "json"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: urtak
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.7
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kunal Shah
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-01 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70275140141100 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70275140141100
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70275140140300 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70275140140300
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: fakeweb
|
38
|
+
requirement: &70275140139520 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70275140139520
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: vcr
|
49
|
+
requirement: &70275140139080 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70275140139080
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rest-client
|
60
|
+
requirement: &70275140138640 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70275140138640
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: &70275140138200 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70275140138200
|
80
|
+
description: Ruby Client for the Urtak REST API
|
81
|
+
email:
|
82
|
+
- kunal@urtak.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- .travis.yml
|
89
|
+
- Gemfile
|
90
|
+
- Rakefile
|
91
|
+
- lib/urtak.rb
|
92
|
+
- lib/urtak/version.rb
|
93
|
+
- spec/base.rb
|
94
|
+
- spec/client_spec.rb
|
95
|
+
- urtak.gemspec
|
96
|
+
homepage: https://github.com/urtak/urtak-rb
|
97
|
+
licenses: []
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project: urtak
|
116
|
+
rubygems_version: 1.8.10
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: Ruby Client for the Urtak REST API
|
120
|
+
test_files:
|
121
|
+
- spec/base.rb
|
122
|
+
- spec/client_spec.rb
|