crowdkit 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 465723a6ac2f11feea2f347b1574cc49bc46a295
4
- data.tar.gz: 527a5d9e1482d98e57f767015eee4792e6276b08
3
+ metadata.gz: 5871fd4155cd37a910ca71ed713bb3aa2aa1cdc3
4
+ data.tar.gz: e6ee0092a2809a341d9fa34b99e6195f6d9cb871
5
5
  SHA512:
6
- metadata.gz: 575299ba50009f42385dac46185aec5e909c456a62b4b38a2cdecd5ece3e3432147d9c79d4f641833dfa8b06be7dd41442ee2b180900e68dd04864b2e44ce69f
7
- data.tar.gz: 386d5c148f30af3b8ca843bddf20d92c7087b81369f4b1bfefea79da269ff19c285466746e6c92b323a92fa73f4fe0e017d5bdcf8d61a99ab2807db5e2e4520d
6
+ metadata.gz: 3c3aebe976fa7d9f57d1aa66335981660beb044ed44df5dda977a0a85bfff8cc4e145fb813d07e3bada220dd50c791f6c6548546e2568f54d99c7b7fcbc491d5
7
+ data.tar.gz: bfe602c7056699168495f8344b47e6360d0571d0e3b6595c39521ce2e5734346d561603bebde09b328884a4b5c5d62c248b7fd323b15bab14d4c6302d7572797
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -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.0 ruby lib
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.0"
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-09"
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 = [
@@ -1,4 +1,5 @@
1
1
  require 'sawyer'
2
+ require 'ruby-progressbar'
2
3
  require 'crowdkit/version'
3
4
  require 'crowdkit/core_ext/hash'
4
5
  require 'crowdkit/core_ext/array'
@@ -8,23 +8,22 @@ module Crowdkit
8
8
  extend Forwardable
9
9
  include RequestMethods
10
10
  attr_accessor :stored_params
11
- attr_reader :config, :client
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 _config, and _client
18
- #get set. We override this in Client as it's the root of the API.
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 || @config.auto_paginate
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
@@ -115,7 +115,7 @@ module Crowdkit
115
115
  # Print only response body
116
116
  #
117
117
  def inspect
118
- "#<#{self.class.name} @data=\"#{self.data}\">"
118
+ self.data.inspect
119
119
  end
120
120
  end
121
121
  end
@@ -4,6 +4,7 @@ module Crowdkit
4
4
  #chaining.
5
5
  class Client < API
6
6
  attr_accessor :last_response
7
+ attr_reader :config
7
8
 
8
9
  #Accepts a hash of configuration overrides or a Config object
9
10
  def initialize(overrides, &block)
@@ -3,5 +3,7 @@ module Crowdkit
3
3
  def get
4
4
  do_get("account")
5
5
  end
6
+ alias :find :get
7
+ alias :show :get
6
8
  end
7
- end
9
+ end
@@ -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
@@ -10,6 +10,7 @@ module Crowdkit
10
10
  do_get("units/#{unit_id}")
11
11
  end
12
12
  alias :find :get
13
+ alias :show :get
13
14
 
14
15
  def list(*args)
15
16
  arguments(args, required: [:job_id])
@@ -114,10 +114,10 @@ module Crowdkit
114
114
 
115
115
  def data
116
116
  @data ||=
117
- if (body = @response[:body]) && !body.empty?
117
+ if (body = @response.body) && !body.empty?
118
118
  if body.is_a?(String) &&
119
- @response[:response_headers] &&
120
- @response[:response_headers][:content_type] =~ /json/
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 unless data.is_a?(Hash) && !Array(data[:errors]).empty?
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[:status]} - "
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.0
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-09 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sawyer