Skip to content

Commit b263b64

Browse files
authored
Merge pull request #13 from test-IO/feature/add_bulk_create_with_to_gig_invitations
[#EPMTIOOPS-3103] Add bulk create of gig invitations to the gem
2 parents 1c32c9f + 3a88308 commit b263b64

File tree

9 files changed

+80
-8
lines changed

9 files changed

+80
-8
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
cirro-ruby-client (1.3.0)
4+
cirro-ruby-client (1.4.0)
55
faraday (< 1.2.0)
66
faraday_middleware
77
json_api_client (>= 1.10.0)

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,15 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
4343
## License
4444

4545
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46+
47+
## Usage
48+
49+
#### Bulk create gig invitations
50+
51+
```ruby
52+
gig = CirroIO::Client::Gig.load(id: 1)
53+
filter = CirroIO::Client::WorkerFilter.new(filter_query: '{ "app_worker_id": { "$in": [1,2,3] } }')
54+
invitation = CirroIO::Client::GigInvitation.new(gig: gig)
55+
56+
invitation.bulk_create_with(filter, auto_accept: true) # by default auto_accept is false
57+
```

lib/cirro_io/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require 'cirro_io/client/response_debugging_middleware'
66
require 'cirro_io/client/jwt_authentication'
77
require 'cirro_io/client/base'
8+
require 'cirro_io/client/bulk_action_helper'
89
require 'cirro_io/client/gig_invitation'
910
require 'cirro_io/client/app_user'
1011
require 'cirro_io/client/app_worker'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module CirroIO
2+
module Client
3+
module BulkActionHelper
4+
def format_to_dashed_keys(params)
5+
params.deep_transform_keys { |key| key.to_s.gsub('_', '-') }
6+
end
7+
end
8+
end
9+
end

lib/cirro_io/client/gig.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module CirroIO
22
module Client
33
class Gig < Base
4+
include CirroIO::Client::BulkActionHelper
5+
46
has_one :worker_filter
57
has_many :gig_tasks
68
has_many :gig_results
@@ -34,12 +36,6 @@ def bulk_archive_with(gig_results, gig_time_activities)
3436
self.class.parser.parse(self.class, response).first
3537
end
3638
# rubocop:enable Metrics/AbcSize
37-
38-
private
39-
40-
def format_to_dashed_keys(params)
41-
params.deep_transform_keys { |key| key.to_s.gsub('_', '-') }
42-
end
4339
end
4440
end
4541
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
module CirroIO
22
module Client
33
class GigInvitation < Base
4+
include CirroIO::Client::BulkActionHelper
5+
6+
has_one :gig
7+
8+
def bulk_create_with(worker_filter, auto_accept: false)
9+
payload = { data: { attributes: attributes.merge(worker_filter: worker_filter.attributes, auto_accept: auto_accept) } }
10+
11+
response = self.class.custom_post("bulk/gigs/#{gig.id}/gig_invitations", format_to_dashed_keys(payload))
12+
13+
self.class.parser.parse(self.class, response)
14+
end
415
end
516
end
617
end

lib/cirro_io/client/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# rubocop:disable Style/MutableConstant
22
module CirroIO
33
module Client
4-
VERSION = '1.3.0'
4+
VERSION = '1.4.0'
55
end
66
end
77
# rubocop:enable Style/MutableConstant
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
RSpec.describe CirroIO::Client::GigInvitation do
2+
describe 'bulk_create_with' do
3+
before do
4+
configure_api_client
5+
end
6+
7+
let(:gig) { CirroIO::Client::Gig.load(id: 1) }
8+
let(:gig_invitation) { described_class.new(gig: gig) }
9+
10+
let(:worker_filter) { CirroIO::Client::WorkerFilter.new(filter_query: '{}') }
11+
12+
it 'bulk create a gig with gig tasks and filter query' do
13+
request_url = "#{test_site}/v1/bulk/gigs/#{gig.id}/gig_invitations"
14+
stub_request(:post, request_url).to_return(body: File.read('./spec/fixtures/gig_invitations.json'),
15+
headers: { 'Content-Type' => 'application/json' })
16+
17+
created_invs = gig_invitation.bulk_create_with(worker_filter)
18+
19+
expect(created_invs.count).to eq(2)
20+
21+
request_body = {
22+
data: {
23+
attributes: {
24+
type: 'gig-invitations',
25+
'worker-filter': {
26+
type: 'worker-filters',
27+
'filter-query': '{}',
28+
},
29+
'auto-accept': false,
30+
},
31+
},
32+
}
33+
34+
expect(a_request(:post, request_url).with(body: request_body.to_json)).to have_been_made
35+
end
36+
end
37+
end

spec/fixtures/gig_invitations.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"data": [
3+
{ "id": "26", "type": "gig-invitations", "attributes": { "status": "accepted", "gig-id": 1, "app-worker-id": 2 } },
4+
{ "id": "27", "type": "gig-invitations", "attributes": { "status": "accepted", "gig-id": 1, "app-worker-id": 3 } }
5+
]
6+
}

0 commit comments

Comments
 (0)