scrapinghub-client 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5388fb17c08f77b3091bdb87b8be779237f21404
4
- data.tar.gz: 3756c4dcaefbf715608a9d958beb986f18b6f8da
3
+ metadata.gz: 3511f325b2c1cc5ecb3757701a6ff3bc837f57ff
4
+ data.tar.gz: c32c5d71fe5f8fec373efbe530f3e704ae28d80f
5
5
  SHA512:
6
- metadata.gz: 457ceddece99e63f370213e5b17a667d414d315f750cc7ff675dc98e7ce56f179c03fa84b9d73c6951511a6adb2e68c80ef28bfccfe3fa9cc7ea19ec305a05e6
7
- data.tar.gz: ed0dcb6729211f0dc44e57ebe047e71ccc8ea87b24b21e1b7d30ca6be223c3f361f61e905ff005c15ce3d9ef9d38f96e60513e97c694db9bad92f3b62407f38d
6
+ metadata.gz: 9788f21ed29f22d3d65652243a8585f733e5383e5e1bfe7712f1532d10f03269f7759d877c061c9c6957a554cdf776bd3d1f0b35d4f3d21e4371772e93ef2e2d
7
+ data.tar.gz: 8af726be06460cff06d67db37f245d167a3c97a6de391c6e08a4bd62e3a7ff23e6f2a197e2ee3d77d9699f25fcc338cfedbeee9fa4834cdaa1d9dc4257df72b5
data/README.md CHANGED
@@ -8,7 +8,7 @@ Scrapinghub client
8
8
 
9
9
  Ruby client for the [Scrapinghub API][api]. So far it only supports the [Jobs API][jobs-api] (pull requests welcome).
10
10
 
11
- This library tries to take an FP-ish approach. It uses the [contracts gem][contracts] for validating function input and output types (see the [docs][] for the full list of functions and their types) and the [kleisli gem][kleisli] for returning composition-friendly output types. Outputs will be a `Try::Failure` if an exception was raised (e.g. a network timeout), a `Left` if the Scrapinghub API returns failure, or a `Right` if the operation was successful.
11
+ This library tries to take an FP-ish approach. It uses the [contracts gem][contracts] for validating function input and output types (see the [docs][] for the full list of functions and their types) and the [kleisli gem][kleisli] for returning composition-friendly output types. Outputs will be a `Left` if the Scrapinghub API returns failure or if an exception was raised (e.g. a network timeout), or a `Right` if the operation was successful.
12
12
 
13
13
  The Kleisli gem [introductory blog post][kleisli-blog] gives some great examples on how to work with the output types.
14
14
 
@@ -32,7 +32,7 @@ require "scrapinghub-client"
32
32
  j = Scrapinghub::Jobs.new(api_key: 'abc123')
33
33
  j.schedule(project: 123, spider: "foo", add_tag: "bar", extra: { DOWNLOAD_DELAY: "0.5" })
34
34
  .fmap{|r| puts "Job scheduled! Jobid: #{r['jobid']}"}
35
- .or{|f| puts "Failed to schedule job! Reason: #{f.inspect}"}
35
+ .or{|f| puts "Failed to schedule job! Reason: #{f.value}"}
36
36
  ```
37
37
 
38
38
  [travis]: https://travis-ci.org/abevoelker/scrapinghub-client
@@ -25,7 +25,7 @@ module Scrapinghub
25
25
  :state => Optional[Or["pending", "running", "finished"]],
26
26
  :has_tag => Optional[Or[String, ArrayOf[String]]],
27
27
  :lacks_tag => Optional[Or[String, ArrayOf[String]]],
28
- :count => Optional[Nat] ] => Or[Kleisli::Try, Kleisli::Either]
28
+ :count => Optional[Nat] ] => Kleisli::Either
29
29
  # Retrieve information about jobs.
30
30
  #
31
31
  # @param project [Fixnum] the project's numeric ID
@@ -41,13 +41,13 @@ module Scrapinghub
41
41
  # containing the given tag(s)
42
42
  # @param count [Fixnum] (optional) maximum number of jobs to return
43
43
  #
44
- # @return [Kleisli::Try, Kleisli::Either] a Kleisli::Try if a low-level
45
- # exception is raised (e.g. the host is down), a Kleisli::Either::Left
46
- # if validation fails (e.g. bad authentication), or a
47
- # Kleisli::Either::Right if everything was successful.
44
+ # @return [Kleisli::Left] if validation fails (e.g. bad authentication) or
45
+ # if there were any low-level exceptions (e.g. the host is down), with a
46
+ # message detailing the failure.
47
+ # @return [Kleisli::Right] if the operation was successful.
48
48
  def list(args)
49
49
  options = { query: args, basic_auth: { username: @api_key } }
50
- Try { self.class.get("/api/jobs/list.json", options) } >-> response {
50
+ Try { self.class.get("/api/jobs/list.json", options) }.to_either >-> response {
51
51
  if response.code == 200
52
52
  Right(response)
53
53
  else
@@ -60,7 +60,7 @@ module Scrapinghub
60
60
  :spider => String,
61
61
  :add_tag => Optional[Or[String, ArrayOf[String]]],
62
62
  :priority => Optional[Or[0, 1, 2, 3, 4]],
63
- :extra => Optional[HashOf[Symbol => String]] ] => Or[Kleisli::Try, Kleisli::Either]
63
+ :extra => Optional[HashOf[Symbol => String]] ] => Kleisli::Either
64
64
  # Schedule a job.
65
65
  #
66
66
  # @param project [Fixnum] the project's numeric ID
@@ -71,14 +71,14 @@ module Scrapinghub
71
71
  # @param extra [Hash] (optional) extra parameters passed as spider
72
72
  # arguments
73
73
  #
74
- # @return [Kleisli::Try, Kleisli::Either] a Kleisli::Try if a low-level
75
- # exception is raised (e.g. the host is down), a Kleisli::Either::Left
76
- # if validation fails (e.g. bad authentication), or a
77
- # Kleisli::Either::Right if everything was successful.
74
+ # @return [Kleisli::Left] if validation fails (e.g. bad authentication) or
75
+ # if there were any low-level exceptions (e.g. the host is down), with a
76
+ # message detailing the failure.
77
+ # @return [Kleisli::Right] if the operation was successful.
78
78
  def schedule(args)
79
79
  extra = args.delete(:extra) || {}
80
80
  options = { body: args.merge(extra), basic_auth: { username: @api_key } }
81
- Try { self.class.post("/api/schedule.json", options) } >-> response {
81
+ Try { self.class.post("/api/schedule.json", options) }.to_either >-> response {
82
82
  if response.code == 200
83
83
  Right(response)
84
84
  else
@@ -94,7 +94,7 @@ module Scrapinghub
94
94
  :has_tag => Optional[Or[String, ArrayOf[String]]],
95
95
  :lacks_tag => Optional[Or[String, ArrayOf[String]]],
96
96
  :add_tag => Optional[Or[String, ArrayOf[String]]],
97
- :remove_tag => Optional[Or[String, ArrayOf[String]]] ] => Or[Kleisli::Try, Kleisli::Either]
97
+ :remove_tag => Optional[Or[String, ArrayOf[String]]] ] => Kleisli::Either
98
98
  # Update information about jobs.
99
99
  #
100
100
  # @param project [Fixnum] the project's numeric ID
@@ -112,13 +112,13 @@ module Scrapinghub
112
112
  # @param remove_tag [String, Array<String>] (optional) tag(s) to remove
113
113
  # from the queried jobs
114
114
  #
115
- # @return [Kleisli::Try, Kleisli::Either] a Kleisli::Try if a low-level
116
- # exception is raised (e.g. the host is down), a Kleisli::Either::Left
117
- # if validation fails (e.g. bad authentication), or a
118
- # Kleisli::Either::Right if everything was successful.
115
+ # @return [Kleisli::Left] if validation fails (e.g. bad authentication) or
116
+ # if there were any low-level exceptions (e.g. the host is down), with a
117
+ # message detailing the failure.
118
+ # @return [Kleisli::Right] if the operation was successful.
119
119
  def update(args)
120
120
  options = { body: args, basic_auth: { username: @api_key } }
121
- Try { self.class.post("/api/jobs/update.json", options) } >-> response {
121
+ Try { self.class.post("/api/jobs/update.json", options) }.to_either >-> response {
122
122
  if response.code == 200
123
123
  Right(response)
124
124
  else
@@ -128,19 +128,19 @@ module Scrapinghub
128
128
  end
129
129
 
130
130
  Contract KeywordArgs[:project => Nat,
131
- :job => Or[String, ArrayOf[String]] ] => Or[Kleisli::Try, Kleisli::Either]
131
+ :job => Or[String, ArrayOf[String]] ] => Kleisli::Either
132
132
  # Delete one or more jobs.
133
133
  #
134
134
  # @param project [Fixnum] the project's numeric ID
135
135
  # @param job [String, Array<String>] the ID of a specific job to delete
136
136
  #
137
- # @return [Kleisli::Try, Kleisli::Either] a Kleisli::Try if a low-level
138
- # exception is raised (e.g. the host is down), a Kleisli::Either::Left
139
- # if validation fails (e.g. bad authentication), or a
140
- # Kleisli::Either::Right if everything was successful.
137
+ # @return [Kleisli::Left] if validation fails (e.g. bad authentication) or
138
+ # if there were any low-level exceptions (e.g. the host is down), with a
139
+ # message detailing the failure.
140
+ # @return [Kleisli::Right] if the operation was successful.
141
141
  def delete(args)
142
142
  options = { body: args, basic_auth: { username: @api_key } }
143
- Try { self.class.post("/api/jobs/delete.json", options) } >-> response {
143
+ Try { self.class.post("/api/jobs/delete.json", options) }.to_either >-> response {
144
144
  if response.code == 200
145
145
  Right(response)
146
146
  else
@@ -150,19 +150,19 @@ module Scrapinghub
150
150
  end
151
151
 
152
152
  Contract KeywordArgs[:project => Nat,
153
- :job => String ] => Or[Kleisli::Try, Kleisli::Either]
153
+ :job => String ] => Kleisli::Either
154
154
  # Stop one or more running jobs.
155
155
  #
156
156
  # @param project [Fixnum] the project's numeric ID
157
157
  # @param job [String] the ID of a job to stop
158
158
  #
159
- # @return [Kleisli::Try, Kleisli::Either] a Kleisli::Try if a low-level
160
- # exception is raised (e.g. the host is down), a Kleisli::Either::Left
161
- # if validation fails (e.g. bad authentication), or a
162
- # Kleisli::Either::Right if everything was successful.
159
+ # @return [Kleisli::Left] if validation fails (e.g. bad authentication) or
160
+ # if there were any low-level exceptions (e.g. the host is down), with a
161
+ # message detailing the failure.
162
+ # @return [Kleisli::Right] if the operation was successful.
163
163
  def stop(args)
164
164
  options = { body: args, basic_auth: { username: @api_key } }
165
- Try { self.class.post("/api/jobs/stop.json", options) } >-> response {
165
+ Try { self.class.post("/api/jobs/stop.json", options) }.to_either >-> response {
166
166
  if response.code == 200
167
167
  Right(response)
168
168
  else
@@ -1,3 +1,3 @@
1
1
  module Scrapinghub
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
17
17
 
18
18
  s.add_dependency "contracts", "~> 0.11"
19
- s.add_dependency "kleisli"
19
+ s.add_dependency "kleisli", ">= 0.2.7"
20
20
  s.add_dependency "httparty"
21
21
 
22
22
  s.add_development_dependency "rake"
@@ -5,8 +5,8 @@ shared_examples "connection_refused_returns_try" do
5
5
  stub_request(:any, "dash.scrapinghub.com").to_timeout
6
6
  end
7
7
 
8
- it "returns a Try::Failure when host is down" do
9
- expect(jobs.send(action, args)).to be_a Kleisli::Try::Failure
8
+ it "returns a Kleisli::Either::Left when host is down" do
9
+ expect(jobs.send(action, args)).to be_a Kleisli::Either::Left
10
10
  end
11
11
  end
12
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrapinghub-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abe Voelker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-30 00:00:00.000000000 Z
11
+ date: 2015-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.2.7
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.2.7
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: httparty
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  requirements: []
195
195
  rubyforge_project:
196
- rubygems_version: 2.4.5
196
+ rubygems_version: 2.4.5.1
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: Ruby client for Scrapinghub API