Skip to content

Commit 68e95e3

Browse files
authored
Gig bulk create (#7)
* bulk skeleton * bulk actions * version bump * stale code
1 parent 08b55d7 commit 68e95e3

15 files changed

+184
-13
lines changed

Gemfile.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
PATH
22
remote: .
33
specs:
4-
cirro-ruby-client (1.0.1)
4+
cirro-ruby-client (1.1.0)
5+
faraday_middleware
56
json_api_client
67
jwt
78

cirro-ruby-client.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
2727

2828
spec.add_runtime_dependency 'jwt'
2929
spec.add_runtime_dependency 'json_api_client'
30+
spec.add_runtime_dependency 'faraday_middleware'
3031
end

lib/cirro_io/client.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
require 'cirro_io/client/gig_invitation'
88
require 'cirro_io/client/app_user'
99
require 'cirro_io/client/app_worker'
10+
require 'cirro_io/client/worker_invitation_filter'
11+
require 'cirro_io/client/gig_task'
12+
require 'cirro_io/client/gig'
1013

1114
module CirroIO
1215
module Client

lib/cirro_io/client/app_user.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
module CirroIO
22
module Client
33
class AppUser < Base
4-
def self.resource_name
5-
'app-users'
6-
end
74
end
85
end
96
end

lib/cirro_io/client/app_worker.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ module Client
33
class AppWorker < Base
44
has_one :app_user
55
has_many :gig_invitations
6-
7-
def self.resource_name
8-
'app-workers'
9-
end
106
end
117
end
128
end

lib/cirro_io/client/base.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ def self.site=(url)
99
super(url)
1010
connection.faraday.url_prefix = url
1111
end
12+
13+
def self.custom_post(endpoint, payload)
14+
custom_connection.post(endpoint, payload.to_json)
15+
end
16+
17+
def self.custom_connection
18+
Faraday.new(url: "#{CirroIO::Client.configuration.site}/#{CirroIO::Client.configuration.api_version}") do |conn|
19+
conn.request :json
20+
conn.response :json
21+
conn.use CirroIO::Client::JwtAuthentication
22+
conn.use JsonApiClient::Middleware::Status, {}
23+
end
24+
end
1225
end
1326
end
1427
end

lib/cirro_io/client/gig.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module CirroIO
2+
module Client
3+
class Gig < Base
4+
has_one :worker_invitation_filter
5+
has_many :gig_tasks
6+
7+
# rubocop:disable Metrics/AbcSize
8+
def bulk_create_with(attrs)
9+
payload = { data: { attributes: attributes } }
10+
11+
if attrs[:gig_tasks]
12+
payload[:data][:relationships] ||= {}
13+
payload[:data][:relationships][:gig_tasks] = attrs[:gig_tasks].map(&:attributes)
14+
end
15+
16+
if attrs[:worker_invitation_filter]
17+
payload[:data][:relationships] ||= {}
18+
payload[:data][:relationships][:worker_invitation_filter] = attrs[:worker_invitation_filter].attributes
19+
end
20+
21+
response = self.class.custom_post('bulk/gigs', payload)
22+
23+
self.class.parser.parse(self.class, response).first
24+
end
25+
# rubocop:enable Metrics/AbcSize
26+
end
27+
end
28+
end
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
module CirroIO
22
module Client
33
class GigInvitation < Base
4-
def self.resource_name
5-
'gig-invitations'
6-
end
74
end
85
end
96
end

lib/cirro_io/client/gig_task.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module CirroIO
2+
module Client
3+
class GigTask < Base
4+
end
5+
end
6+
end

lib/cirro_io/client/response_debugging_middleware.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module CirroIO
33
module Client
44
class ResponseDebuggingMiddleware < Faraday::Response::Middleware
55
def on_complete(env)
6-
# binding.pry
6+
binding.pry # rubocop:disable Lint/Debugger
77
end
88
end
99
end

0 commit comments

Comments
 (0)