kempelen 1.0.0
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 +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +22 -0
- data/Gemfile +5 -0
- data/Guardfile +42 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +27 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/examples/approve_assignment.rb +16 -0
- data/examples/create_hit.rb +20 -0
- data/examples/force_expire_hit.rb +16 -0
- data/examples/get_account_balance.rb +16 -0
- data/examples/get_assignments_for_hit.rb +16 -0
- data/examples/get_hit.rb +16 -0
- data/examples/get_reviewable_hits.rb +16 -0
- data/examples/reject_assignment.rb +16 -0
- data/examples/set_hit_as_reviewing.rb +16 -0
- data/kempelen.gemspec +35 -0
- data/lib/kempelen.rb +35 -0
- data/lib/kempelen/API/client.rb +45 -0
- data/lib/kempelen/API/common/answers.rb +34 -0
- data/lib/kempelen/API/common/assignment.rb +37 -0
- data/lib/kempelen/API/common/price.rb +26 -0
- data/lib/kempelen/API/common/question_form_answers.rb +57 -0
- data/lib/kempelen/API/operations/approve_assignment.rb +17 -0
- data/lib/kempelen/API/operations/assignment_operation.rb +36 -0
- data/lib/kempelen/API/operations/base.rb +71 -0
- data/lib/kempelen/API/operations/create_hit.rb +55 -0
- data/lib/kempelen/API/operations/force_expire_hit.rb +25 -0
- data/lib/kempelen/API/operations/get_account_balance.rb +30 -0
- data/lib/kempelen/API/operations/get_assignments_for_hit.rb +42 -0
- data/lib/kempelen/API/operations/get_hit.rb +25 -0
- data/lib/kempelen/API/operations/get_reviewable_hits.rb +64 -0
- data/lib/kempelen/API/operations/hit_operation.rb +23 -0
- data/lib/kempelen/API/operations/parameters.rb +40 -0
- data/lib/kempelen/API/operations/register_hit_type.rb +47 -0
- data/lib/kempelen/API/operations/reject_assignment.rb +17 -0
- data/lib/kempelen/API/operations/set_hit_as_reviewing.rb +34 -0
- data/lib/kempelen/API/responses/account_balance_response.rb +27 -0
- data/lib/kempelen/API/responses/base.rb +32 -0
- data/lib/kempelen/API/responses/empty_response.rb +17 -0
- data/lib/kempelen/API/responses/error_response.rb +32 -0
- data/lib/kempelen/API/responses/get_assignments_response.rb +31 -0
- data/lib/kempelen/API/responses/hit_response.rb +66 -0
- data/lib/kempelen/API/responses/reviewable_hits_response.rb +38 -0
- data/lib/kempelen/version.rb +3 -0
- metadata +260 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
module Kempelen
|
2
|
+
module API
|
3
|
+
module Operations
|
4
|
+
class GetAccountBalance < Base
|
5
|
+
AWS_OPERATION_NAME = "GetAccountBalance".freeze
|
6
|
+
AWS_RESPONSE_OBJECT = "GetAccountBalanceResponse".freeze
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
super(client)
|
10
|
+
|
11
|
+
@response_object = AWS_RESPONSE_OBJECT
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_parameters
|
15
|
+
@parameters[:operation] = AWS_OPERATION_NAME
|
16
|
+
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def perform_operation
|
21
|
+
create_request_string
|
22
|
+
|
23
|
+
super
|
24
|
+
|
25
|
+
Kempelen::API::Responses::AccountBalanceResponse.new(@raw_response)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Kempelen
|
2
|
+
module API
|
3
|
+
module Operations
|
4
|
+
class GetAssignmentsForHit < HitOperation
|
5
|
+
attr_accessor :assignment_status
|
6
|
+
attr_accessor :page_size
|
7
|
+
attr_accessor :page_number
|
8
|
+
|
9
|
+
AWS_OPERATION_NAME = "GetAssignmentsForHIT".freeze
|
10
|
+
AWS_RESPONSE_OBJECT = "GetAssignmentsForHITResponse".freeze
|
11
|
+
AWS_DEFAULT_PAGE_SIZE = 10
|
12
|
+
AWS_DEFAULT_PAGE_NUMBER = 1
|
13
|
+
|
14
|
+
def initialize(client, hit_id)
|
15
|
+
super(client, hit_id)
|
16
|
+
|
17
|
+
@operation_name = AWS_OPERATION_NAME
|
18
|
+
@response_object = AWS_RESPONSE_OBJECT
|
19
|
+
@assignment_status = nil
|
20
|
+
@page_size = AWS_DEFAULT_PAGE_SIZE
|
21
|
+
@page_number = AWS_DEFAULT_PAGE_NUMBER
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_parameters
|
25
|
+
@parameters[:assignment_status] = @assignment_status
|
26
|
+
@parameters[:page_size] = @page_size
|
27
|
+
@parameters[:page_number] = @page_number
|
28
|
+
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def perform_operation
|
33
|
+
create_request_string
|
34
|
+
|
35
|
+
super
|
36
|
+
|
37
|
+
Kempelen::API::Responses::GetAssignmentsResponse.new(@raw_response)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Kempelen
|
2
|
+
module API
|
3
|
+
module Operations
|
4
|
+
class GetHit < HitOperation
|
5
|
+
AWS_OPERATION_NAME = "GetHIT".freeze
|
6
|
+
AWS_RESPONSE_OBJECT = "GetHITResponse".freeze
|
7
|
+
|
8
|
+
def initialize(client, hit_id)
|
9
|
+
super(client, hit_id)
|
10
|
+
|
11
|
+
@operation_name = AWS_OPERATION_NAME
|
12
|
+
@response_object = AWS_RESPONSE_OBJECT
|
13
|
+
end
|
14
|
+
|
15
|
+
def perform_operation
|
16
|
+
create_request_string
|
17
|
+
|
18
|
+
super
|
19
|
+
|
20
|
+
Kempelen::API::Responses::HitResponse.new(@raw_response)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Kempelen
|
2
|
+
module API
|
3
|
+
module Operations
|
4
|
+
class GetReviewableHits < Base
|
5
|
+
attr_accessor :hit_type_id
|
6
|
+
attr_accessor :status
|
7
|
+
attr_accessor :page_size
|
8
|
+
attr_accessor :page_number
|
9
|
+
attr_accessor :sort_property
|
10
|
+
attr_accessor :sort_direction
|
11
|
+
|
12
|
+
AWS_OPERATION_NAME = "GetReviewableHITs".freeze
|
13
|
+
AWS_RESPONSE_OBJECT = "GetReviewableHITsResponse".freeze
|
14
|
+
AWS_DEFAULT_PAGE_SIZE = 100
|
15
|
+
AWS_DEFAULT_PAGE_NUMBER = 1
|
16
|
+
|
17
|
+
def initialize(client, hit_type_id)
|
18
|
+
super(client)
|
19
|
+
|
20
|
+
@response_object = AWS_RESPONSE_OBJECT
|
21
|
+
@hit_type_id = hit_type_id
|
22
|
+
@status = :reviewable
|
23
|
+
@page_size = AWS_DEFAULT_PAGE_SIZE
|
24
|
+
@page_number = AWS_DEFAULT_PAGE_NUMBER
|
25
|
+
@sort_property = :enumeration
|
26
|
+
@sort_direction = :descending
|
27
|
+
end
|
28
|
+
|
29
|
+
def amazon_status
|
30
|
+
@status.to_s.capitalize.freeze
|
31
|
+
end
|
32
|
+
|
33
|
+
def amazon_sort_property
|
34
|
+
@sort_property.to_s.capitalize.freeze
|
35
|
+
end
|
36
|
+
|
37
|
+
def amazon_sort_direction
|
38
|
+
@sort_direction.to_s.capitalize.freeze
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_parameters
|
42
|
+
@parameters[:operation] = AWS_OPERATION_NAME
|
43
|
+
@parameters[:hit_type_id] = @hit_type_id
|
44
|
+
@parameters[:status] = amazon_status
|
45
|
+
@parameters[:page_size] = @page_size
|
46
|
+
@parameters[:page_number] = @page_number
|
47
|
+
@parameters[:sort_property] = amazon_sort_property
|
48
|
+
@parameters[:sort_direction] = amazon_sort_direction
|
49
|
+
|
50
|
+
super
|
51
|
+
end
|
52
|
+
|
53
|
+
def perform_operation
|
54
|
+
create_request_string
|
55
|
+
|
56
|
+
super
|
57
|
+
|
58
|
+
Kempelen::API::Responses::ReviewableHitsResponse.new(@raw_response)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Kempelen
|
2
|
+
module API
|
3
|
+
module Operations
|
4
|
+
class HitOperation < Base
|
5
|
+
attr_accessor :hit_id
|
6
|
+
attr_accessor :operation_name
|
7
|
+
|
8
|
+
def initialize(client, hit_id)
|
9
|
+
super(client)
|
10
|
+
|
11
|
+
@hit_id = hit_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_parameters
|
15
|
+
@parameters[:operation] = @operation_name
|
16
|
+
@parameters[:hit_id] = @hit_id
|
17
|
+
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Kempelen
|
2
|
+
module API
|
3
|
+
module Operations
|
4
|
+
PARAMETERS = {
|
5
|
+
service: "Service".freeze,
|
6
|
+
operation: "Operation".freeze,
|
7
|
+
access_key: "AWSAccessKeyId".freeze,
|
8
|
+
timestamp: "Timestamp".freeze,
|
9
|
+
signature: "Signature".freeze,
|
10
|
+
hit_type_id: "HITTypeId".freeze,
|
11
|
+
layout_id: "HITLayoutId".freeze,
|
12
|
+
lifetime_in_seconds: "LifetimeInSeconds".freeze,
|
13
|
+
max_assignments: "MaxAssignments".freeze,
|
14
|
+
requester_annotation: "RequesterAnnotation".freeze,
|
15
|
+
unique_request_token: "UniqueRequestToken".freeze,
|
16
|
+
hit_id: "HITId".freeze,
|
17
|
+
status: "Status".freeze,
|
18
|
+
page_size: "PageSize".freeze,
|
19
|
+
page_number: "PageNumber".freeze,
|
20
|
+
sort_property: "SortProperty".freeze,
|
21
|
+
sort_direction: "SortDirection".freeze,
|
22
|
+
assignment_id: "AssignmentId".freeze,
|
23
|
+
requester_feedback: "RequesterFeedback".freeze,
|
24
|
+
assignment_status: "AssignmentStatus".freeze,
|
25
|
+
revert: "Revert".freeze,
|
26
|
+
title: "Title".freeze,
|
27
|
+
description: "Description".freeze,
|
28
|
+
reward: "Reward".freeze,
|
29
|
+
assignment_duration: "AssignmentDurationInSeconds".freeze,
|
30
|
+
keywords: "Keywords".freeze,
|
31
|
+
auto_approval_delay: "AutoApprovalDelayInSeconds".freeze,
|
32
|
+
qualification_requirement: "QualificationRequirement".freeze
|
33
|
+
}
|
34
|
+
|
35
|
+
ARRAY_PARAMETERS = {
|
36
|
+
layout_parameters: "HITLayoutParameter".freeze
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Kempelen
|
2
|
+
module API
|
3
|
+
module Operations
|
4
|
+
class RegisterHitType < Base
|
5
|
+
attr_accessor :title
|
6
|
+
attr_accessor :description
|
7
|
+
attr_accessor :reward
|
8
|
+
attr_accessor :assignment_duration
|
9
|
+
attr_accessor :keywords
|
10
|
+
attr_accessor :auto_approval_delay
|
11
|
+
|
12
|
+
# TODO: Support qualification requirements
|
13
|
+
attr_accessor :qualification_requirement
|
14
|
+
|
15
|
+
AWS_OPERATION_NAME = "RegisterHITType".freeze
|
16
|
+
|
17
|
+
def initialize(client, title, description, reward, assignment_duration, &block)
|
18
|
+
super(client)
|
19
|
+
|
20
|
+
@title = title
|
21
|
+
@description = description
|
22
|
+
@reward = reward
|
23
|
+
@assignment_duration = assignment_duration
|
24
|
+
@keywords = []
|
25
|
+
|
26
|
+
yield self unless block == nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def amazon_keywords
|
30
|
+
@keywords.map {|k| k.strip}.join(',')
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_parameters
|
34
|
+
@parameters[:operation] = AWS_OPERATION_NAME
|
35
|
+
@parameters[:title] = @title
|
36
|
+
@parameters[:description] = @description
|
37
|
+
@parameters[:reward] = @reward
|
38
|
+
@parameters[:assignment_duration] = @assignment_duration
|
39
|
+
@parameters[:keywords] = amazon_keywords
|
40
|
+
@parameters[:auto_approval_delay] = @auto_approval_delay
|
41
|
+
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Kempelen
|
2
|
+
module API
|
3
|
+
module Operations
|
4
|
+
class RejectAssignment < AssignmentOperation
|
5
|
+
AWS_OPERATION_NAME = "RejectAssignment".freeze
|
6
|
+
AWS_RESPONSE_OBJECT = "RejectAssignmentResponse".freeze
|
7
|
+
|
8
|
+
def initialize(client, assignment_id, requester_feedback = nil)
|
9
|
+
super(client, assignment_id, requester_feedback)
|
10
|
+
|
11
|
+
@operation_name = AWS_OPERATION_NAME
|
12
|
+
@response_object = AWS_RESPONSE_OBJECT
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Kempelen
|
2
|
+
module API
|
3
|
+
module Operations
|
4
|
+
class SetHitAsReviewing < HitOperation
|
5
|
+
attr_accessor :revert
|
6
|
+
|
7
|
+
AWS_OPERATION_NAME = "SetHITAsReviewing".freeze
|
8
|
+
AWS_RESPONSE_OBJECT = "SetHITAsReviewingResponse".freeze
|
9
|
+
|
10
|
+
def initialize(client, hit_id, revert = false)
|
11
|
+
super(client, hit_id)
|
12
|
+
|
13
|
+
@operation_name = AWS_OPERATION_NAME
|
14
|
+
@response_object = AWS_RESPONSE_OBJECT
|
15
|
+
@revert = revert
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_parameters
|
19
|
+
@parameters[:revert] = @revert
|
20
|
+
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def perform_operation
|
25
|
+
create_request_string
|
26
|
+
|
27
|
+
super
|
28
|
+
|
29
|
+
Kempelen::API::Responses::EmptyResponse.new(@raw_response)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Kempelen
|
2
|
+
module API
|
3
|
+
module Responses
|
4
|
+
class AccountBalanceResponse < Base
|
5
|
+
attr_reader :available_balance
|
6
|
+
attr_reader :on_hold_balance
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
super()
|
10
|
+
|
11
|
+
load_from_response(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_from_response(response)
|
15
|
+
super(response)
|
16
|
+
|
17
|
+
balance_response = response["GetAccountBalanceResult"]
|
18
|
+
unless balance_response.nil?
|
19
|
+
@available_balance = Kempelen::API::Common::Price.create_from_response(balance_response["AvailableBalance"])
|
20
|
+
@on_hold_balance = Kempelen::API::Common::Price.create_from_response(balance_response["OnHoldBalance"])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Kempelen
|
2
|
+
module API
|
3
|
+
module Responses
|
4
|
+
class Base
|
5
|
+
attr_accessor :success
|
6
|
+
attr_accessor :request_id
|
7
|
+
attr_accessor :error
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@success = false
|
11
|
+
@error = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_from_response(response)
|
15
|
+
@request_id = response["OperationRequest"]["RequestId"] rescue nil
|
16
|
+
|
17
|
+
response.each_key do |k|
|
18
|
+
if response[k].has_key?("Request")
|
19
|
+
request_response = response[k]["Request"]
|
20
|
+
@success = (request_response["IsValid"] == "True")
|
21
|
+
|
22
|
+
if request_response.has_key?("Errors")
|
23
|
+
@success = false
|
24
|
+
@error = ErrorResponse.new(request_response["Errors"])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Kempelen
|
2
|
+
module API
|
3
|
+
module Responses
|
4
|
+
class ErrorResponse
|
5
|
+
attr_accessor :code
|
6
|
+
attr_accessor :message
|
7
|
+
attr_accessor :data
|
8
|
+
|
9
|
+
def initialize(response = nil)
|
10
|
+
@data = []
|
11
|
+
|
12
|
+
parse_from_response(response) unless response.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse_from_response(response)
|
16
|
+
error = response["Error"]
|
17
|
+
unless error.nil?
|
18
|
+
@code = error["Code"]
|
19
|
+
@message = error["Message"]
|
20
|
+
end
|
21
|
+
|
22
|
+
data = error["Data"].nil? ? [] : error["Data"]
|
23
|
+
data.each do |data_value|
|
24
|
+
key = data_value["Key"] rescue nil
|
25
|
+
value = data_value["Value"] rescue nil
|
26
|
+
@data << {key: key, value: value}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|