crowdkit 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/crowdkit.gemspec +3 -3
- data/lib/crowdkit.rb +1 -0
- data/lib/crowdkit/api.rb +5 -7
- data/lib/crowdkit/api/response_wrapper.rb +1 -1
- data/lib/crowdkit/client.rb +1 -0
- data/lib/crowdkit/client/account.rb +3 -1
- data/lib/crowdkit/client/jobs.rb +8 -0
- data/lib/crowdkit/client/judgments.rb +8 -0
- data/lib/crowdkit/client/units.rb +1 -0
- data/lib/crowdkit/error.rb +11 -11
- data/spec/crowdkit/client/judgments_spec.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5871fd4155cd37a910ca71ed713bb3aa2aa1cdc3
|
4
|
+
data.tar.gz: e6ee0092a2809a341d9fa34b99e6195f6d9cb871
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c3aebe976fa7d9f57d1aa66335981660beb044ed44df5dda977a0a85bfff8cc4e145fb813d07e3bada220dd50c791f6c6548546e2568f54d99c7b7fcbc491d5
|
7
|
+
data.tar.gz: bfe602c7056699168495f8344b47e6360d0571d0e3b6595c39521ce2e5734346d561603bebde09b328884a4b5c5d62c248b7fd323b15bab14d4c6302d7572797
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/crowdkit.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: crowdkit 0.1.
|
5
|
+
# stub: crowdkit 0.1.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "crowdkit"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Chris Van Pelt"]
|
14
|
-
s.date = "2015-01-
|
14
|
+
s.date = "2015-01-14"
|
15
15
|
s.description = "A flat API client that sits atop the CrowdFlower API"
|
16
16
|
s.email = "vanpelt@crowdflower.com"
|
17
17
|
s.extra_rdoc_files = [
|
data/lib/crowdkit.rb
CHANGED
data/lib/crowdkit/api.rb
CHANGED
@@ -8,23 +8,22 @@ module Crowdkit
|
|
8
8
|
extend Forwardable
|
9
9
|
include RequestMethods
|
10
10
|
attr_accessor :stored_params
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :client
|
12
12
|
attr_writer :auto_pagination
|
13
13
|
|
14
14
|
#We delegate last_response to the attr_accessor of the top level Client
|
15
|
-
def_delegators :client, :last_response, :last_response=
|
15
|
+
def_delegators :client, :config, :last_response, :last_response=
|
16
16
|
|
17
|
-
#This should only be called by API Factory to ensure
|
18
|
-
#
|
17
|
+
#This should only be called by API Factory to ensure _client
|
18
|
+
#gets set. We override this in Client as it's the root of the API.
|
19
19
|
def initialize(options, &block)
|
20
|
-
@config = options.delete(:_config)
|
21
20
|
@client = options.delete(:_client)
|
22
21
|
@stored_params = options
|
23
22
|
with(options)
|
24
23
|
end
|
25
24
|
|
26
25
|
def auto_pagination
|
27
|
-
@auto_pagination ||
|
26
|
+
@auto_pagination || config.auto_paginate
|
28
27
|
end
|
29
28
|
|
30
29
|
# Acts as setter and getter for api requests arguments parsing.
|
@@ -107,7 +106,6 @@ module Crowdkit
|
|
107
106
|
define_method(name) do |*args, &block|
|
108
107
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
109
108
|
options[:_args] = args
|
110
|
-
options[:_config] = @config
|
111
109
|
options[:_client] = @client
|
112
110
|
API::Factory.new(class_name, stored_params.merge(options), &block)
|
113
111
|
end
|
data/lib/crowdkit/client.rb
CHANGED
data/lib/crowdkit/client/jobs.rb
CHANGED
@@ -6,12 +6,19 @@ module Crowdkit
|
|
6
6
|
do_post("jobs", {title: title}.merge(arguments.params))
|
7
7
|
end
|
8
8
|
|
9
|
+
def update(*args)
|
10
|
+
arguments(args, required: [:job_id])
|
11
|
+
|
12
|
+
do_patch("jobs/#{job_id}", arguments.params)
|
13
|
+
end
|
14
|
+
|
9
15
|
def get(*args)
|
10
16
|
arguments(args, required: [:job_id])
|
11
17
|
|
12
18
|
do_get("jobs/#{job_id}")
|
13
19
|
end
|
14
20
|
alias :find :get
|
21
|
+
alias :show :get
|
15
22
|
|
16
23
|
def search(*args)
|
17
24
|
arguments(args)
|
@@ -52,5 +59,6 @@ module Crowdkit
|
|
52
59
|
end
|
53
60
|
|
54
61
|
namespace :units, class_name: "Client::Units"
|
62
|
+
namespace :worksets, class_name: "Client::Worksets"
|
55
63
|
end
|
56
64
|
end
|
@@ -5,5 +5,13 @@ module Crowdkit
|
|
5
5
|
do_get("judgments/#{judgment_id}")
|
6
6
|
end
|
7
7
|
alias :find :get
|
8
|
+
alias :show :get
|
9
|
+
|
10
|
+
def list(*args)
|
11
|
+
arguments(args, required: [:job_id])
|
12
|
+
|
13
|
+
do_get("jobs/#{job_id}/judgments", arguments.params)
|
14
|
+
end
|
15
|
+
alias :all :list
|
8
16
|
end
|
9
17
|
end
|
data/lib/crowdkit/error.rb
CHANGED
@@ -114,10 +114,10 @@ module Crowdkit
|
|
114
114
|
|
115
115
|
def data
|
116
116
|
@data ||=
|
117
|
-
if (body = @response
|
117
|
+
if (body = @response.body) && !body.empty?
|
118
118
|
if body.is_a?(String) &&
|
119
|
-
@response
|
120
|
-
@response[:
|
119
|
+
@response.headers &&
|
120
|
+
@response.headers[:content_type] =~ /json/
|
121
121
|
|
122
122
|
Sawyer::Agent.serializer.decode(body)
|
123
123
|
else
|
@@ -129,19 +129,19 @@ module Crowdkit
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def response_error_summary
|
132
|
-
return nil
|
132
|
+
return nil if errors.empty?
|
133
133
|
|
134
|
-
summary = "\nError summary:\n"
|
135
|
-
summary << data[:errors].join("\n")
|
136
|
-
summary
|
134
|
+
summary = "\nError summary:\n\t"
|
135
|
+
summary << data[:errors].join("\n\t")
|
136
|
+
summary << "\n"
|
137
137
|
end
|
138
138
|
|
139
139
|
def build_error_message
|
140
|
-
return nil if @response.nil?
|
140
|
+
return nil if @response.env.nil?
|
141
141
|
|
142
|
-
message = "#{@response[:method].to_s.upcase} "
|
143
|
-
message << "#{@response[:url]}
|
144
|
-
message << "#{@response
|
142
|
+
message = "#{@response.env[:method].to_s.upcase} "
|
143
|
+
message << "#{@response.env[:url]} - "
|
144
|
+
message << "(#{@response.status}):"
|
145
145
|
message << "#{response_error_summary}" unless response_error_summary.nil?
|
146
146
|
message << " // See: #{documentation_url}" unless documentation_url.nil?
|
147
147
|
message
|
@@ -27,4 +27,30 @@ describe Crowdkit::Client::Judgments do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
describe "list" do
|
32
|
+
let!(:request_stub) { stub_get("/jobs/10/judgments").to_return(fixture_response("judgments/index.json")) }
|
33
|
+
|
34
|
+
context "requests" do
|
35
|
+
it "gets made" do
|
36
|
+
client.judgments(job_id: 10).list
|
37
|
+
expect(request_stub).to have_been_requested
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has all alias" do
|
41
|
+
client.judgments.all(job_id: 10)
|
42
|
+
expect(request_stub).to have_been_requested
|
43
|
+
end
|
44
|
+
|
45
|
+
it "blows up without job_id" do
|
46
|
+
expect { client.judgments.list }.to raise_error Crowdkit::ValidationError
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "response" do
|
51
|
+
it "parses" do
|
52
|
+
expect(client.judgments(job_id: 10).list.length).to eq(3)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
30
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crowdkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Van Pelt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sawyer
|