Class: Scrapinghub::Jobs
- Inherits:
-
Object
- Object
- Scrapinghub::Jobs
- Includes:
- Contracts, HTTParty
- Defined in:
- lib/scrapinghub/jobs.rb
Instance Method Summary collapse
-
#delete(args) ⇒ Kleisli::Try, Kleisli::Either
Delete one or more jobs.
-
#initialize(api_key:) ⇒ Object
constructor
Initialize a new Jobs API client.
-
#list(args) ⇒ Kleisli::Try, Kleisli::Either
Retrieve information about jobs.
-
#schedule(args) ⇒ Kleisli::Try, Kleisli::Either
Schedule a job.
-
#stop(args) ⇒ Kleisli::Try, Kleisli::Either
Stop one or more running jobs.
-
#update(args) ⇒ Kleisli::Try, Kleisli::Either
Update information about jobs.
Constructor Details
#initialize(api_key:) ⇒ Object
Initialize a new Jobs API client
18 19 20 |
# File 'lib/scrapinghub/jobs.rb', line 18 def initialize(api_key:) @api_key = api_key end |
Instance Method Details
#delete(args) ⇒ Kleisli::Try, Kleisli::Either
Delete one or more jobs.
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/scrapinghub/jobs.rb', line 141 def delete(args) = { body: args, basic_auth: { username: @api_key } } Try { self.class.post("/api/jobs/delete.json", ) } >-> response { if response.code == 200 Right(response) else Left(response) end } end |
#list(args) ⇒ Kleisli::Try, Kleisli::Either
Retrieve information about jobs.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/scrapinghub/jobs.rb', line 48 def list(args) = { query: args, basic_auth: { username: @api_key } } Try { self.class.get("/api/jobs/list.json", ) } >-> response { if response.code == 200 Right(response) else Left(response) end } end |
#schedule(args) ⇒ Kleisli::Try, Kleisli::Either
Schedule a job.
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/scrapinghub/jobs.rb', line 78 def schedule(args) extra = args.delete(:extra) || {} = { body: args.merge(extra), basic_auth: { username: @api_key } } Try { self.class.post("/api/schedule.json", ) } >-> response { if response.code == 200 Right(response) else Left(response) end } end |
#stop(args) ⇒ Kleisli::Try, Kleisli::Either
Stop one or more running jobs.
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/scrapinghub/jobs.rb', line 163 def stop(args) = { body: args, basic_auth: { username: @api_key } } Try { self.class.post("/api/jobs/stop.json", ) } >-> response { if response.code == 200 Right(response) else Left(response) end } end |
#update(args) ⇒ Kleisli::Try, Kleisli::Either
Update information about jobs.
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/scrapinghub/jobs.rb', line 119 def update(args) = { body: args, basic_auth: { username: @api_key } } Try { self.class.post("/api/jobs/update.json", ) } >-> response { if response.code == 200 Right(response) else Left(response) end } end |