leggy 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/README.md +195 -2
- data/Rakefile +4 -0
- data/leggy.gemspec +2 -2
- data/lib/leggy.rb +14 -5
- data/lib/leggy/app.rb +1 -2
- data/lib/leggy/crawl.rb +1 -2
- data/lib/leggy/crawl_options.rb +1 -2
- data/lib/leggy/error.rb +4 -0
- data/lib/leggy/error_handler.rb +30 -0
- data/lib/leggy/exceptions.rb +30 -0
- data/lib/leggy/mapping/app.rb +1 -6
- data/lib/leggy/mapping/crawl.rb +1 -1
- data/lib/leggy/mapping/crawl_options.rb +1 -1
- data/lib/leggy/mapping/url.rb +1 -1
- data/lib/leggy/mapping/user.rb +1 -1
- data/lib/leggy/resource/app.rb +3 -6
- data/lib/leggy/resource/crawl.rb +9 -12
- data/lib/leggy/resource/result.rb +20 -0
- data/lib/leggy/resource/url.rb +3 -6
- data/lib/leggy/resource/user.rb +1 -4
- data/lib/leggy/url.rb +1 -2
- data/lib/leggy/user.rb +1 -2
- data/lib/leggy/version.rb +1 -1
- data/spec/cassettes/{leggy.yml → leggy_app.yml} +106 -822
- data/spec/cassettes/leggy_crawl_all.yml +39 -0
- data/spec/cassettes/leggy_crawl_cancel.yml +147 -0
- data/spec/cassettes/leggy_crawl_start.yml +147 -0
- data/spec/cassettes/leggy_crawl_status.yml +183 -0
- data/spec/cassettes/leggy_exception.yml +38 -0
- data/spec/cassettes/leggy_result.yml +147 -0
- data/spec/cassettes/leggy_url.yml +373 -0
- data/spec/cassettes/leggy_user.yml +38 -0
- data/spec/leggy/exceptions_spec.rb +25 -0
- data/spec/leggy/leggy_spec.rb +1 -162
- data/spec/leggy/resource/app_spec.rb +64 -0
- data/spec/leggy/resource/crawl_spec.rb +88 -0
- data/spec/leggy/resource/result_spec.rb +46 -0
- data/spec/leggy/resource/url_spec.rb +59 -0
- data/spec/leggy/resource/user_spec.rb +22 -0
- data/spec/spec_helper.rb +37 -31
- data/spec/support/helpers.rb +26 -0
- data/spec/support/vcr.rb +12 -0
- metadata +48 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7f28d231bf567519d180e03632c738d5557e1ce
|
4
|
+
data.tar.gz: edce7a1ef7ee3123b2aede13b5df5622e7a84c47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbdf3042c82634faae01a3c4b2cbfc6d6265c44099bbaf96d3f01e8e2d03a991c444080021f22ff41c26bf3bbbda2f002fb5ef16ee59f7194dcf5de42b301563
|
7
|
+
data.tar.gz: 53973b207036638ca4b20463cb30ce7149bc5eca45c61088b44dd21a27316ab4c106d880c4465377d3cd0214807da6175d4b5893e8b36540df22f6f7ff765705
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Leggy
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/leggy.svg?style=flat)](https://rubygems.org/gems/leggy)
|
4
|
+
[![Build Status](https://img.shields.io/travis/activefx/leggy.svg?style=flat)](http://travis-ci.org/activefx/leggy)
|
5
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/activefx/leggy.svg?style=flat)](https://codeclimate.com/github/activefx/leggy)
|
6
|
+
[![Test Coverage](https://img.shields.io/codeclimate/coverage/github/activefx/leggy.svg?style=flat)](https://codeclimate.com/github/activefx/leggy/coverage)
|
7
|
+
[![Dependency Status](https://gemnasium.com/activefx/leggy.svg)](https://gemnasium.com/activefx/leggy)
|
8
|
+
|
9
|
+
Leggy is a simple Ruby wrapper for the 80Legs API. Sign up for a new account at [http://80legs.com/](http://80legs.com/) or view the API docs at [http://datafiniti.github.io/80docs/](http://datafiniti.github.io/80docs/). Leggy is built on top of [Resource Kit](https://github.com/digitalocean/resource_kit) and [Kartograph](https://github.com/digitalocean/kartograph) and accepts custom [Faraday](https://github.com/lostisland/faraday) connections.
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
@@ -20,7 +26,194 @@ Or install it yourself as:
|
|
20
26
|
|
21
27
|
## Usage
|
22
28
|
|
23
|
-
|
29
|
+
Before you can use the 80Legs client, you need to configure the API token. You can use the .configure method to do so:
|
30
|
+
|
31
|
+
````ruby
|
32
|
+
Leggy.configure do |config|
|
33
|
+
config.api_token = 'api_token'
|
34
|
+
end
|
35
|
+
````
|
36
|
+
|
37
|
+
Or you can set it as as the `80_LEGS_API_TOKEN` ENV variable:
|
38
|
+
|
39
|
+
````
|
40
|
+
$ export 80_LEGS_API_TOKEN=your_80legs_api_token
|
41
|
+
````
|
42
|
+
|
43
|
+
Sign up for an account and API token at [80legs](http://80legs.com/).
|
44
|
+
|
45
|
+
### Users
|
46
|
+
|
47
|
+
See [http://datafiniti.github.io/80docs/?ruby#users](http://datafiniti.github.io/80docs/?ruby#users) for complete documentation.
|
48
|
+
|
49
|
+
#### Get User Data
|
50
|
+
|
51
|
+
````ruby
|
52
|
+
user = Leggy.users.find(api_token: Leggy.configuration.api_token)
|
53
|
+
user.first_name
|
54
|
+
#=> "Matt"
|
55
|
+
````
|
56
|
+
|
57
|
+
### Apps
|
58
|
+
|
59
|
+
See [http://datafiniti.github.io/80docs/?ruby#apps](http://datafiniti.github.io/80docs/?ruby#apps) for complete documentation.
|
60
|
+
|
61
|
+
#### Get All Apps
|
62
|
+
|
63
|
+
````ruby
|
64
|
+
apps = apps = Leggy.apps.all
|
65
|
+
apps.first.name
|
66
|
+
#=> "TextFromURLListOnly.js"
|
67
|
+
````
|
68
|
+
|
69
|
+
#### Upload an App
|
70
|
+
|
71
|
+
````ruby
|
72
|
+
file = File.read("/path/to/my/eighty_app.js")
|
73
|
+
Leggy.apps.create(name: 'eighty_app', body: file)
|
74
|
+
#=> true
|
75
|
+
````
|
76
|
+
|
77
|
+
For more information on creating an 80app, see: [https://80legs.groovehq.com/knowledge_base/categories/80apps](https://80legs.groovehq.com/knowledge_base/categories/80apps).
|
78
|
+
|
79
|
+
#### Get a Specific App
|
80
|
+
|
81
|
+
````ruby
|
82
|
+
app = Leggy.apps.find(name: 'TextFromURLListOnly.js')
|
83
|
+
app.name
|
84
|
+
#=> "TextFromURLListOnly.js"
|
85
|
+
````
|
86
|
+
|
87
|
+
#### Delete an App
|
88
|
+
|
89
|
+
*CAUTION* This action cannot be undone.
|
90
|
+
|
91
|
+
````ruby
|
92
|
+
Leggy.apps.delete(name: 'sample_delete')
|
93
|
+
#=> true
|
94
|
+
````
|
95
|
+
|
96
|
+
### Url Lists
|
97
|
+
|
98
|
+
See [http://datafiniti.github.io/80docs/?ruby#url-lists](http://datafiniti.github.io/80docs/?ruby#url-lists) for complete documentation.
|
99
|
+
|
100
|
+
#### Upload Url List
|
101
|
+
|
102
|
+
With the list.json file as follows:
|
103
|
+
|
104
|
+
````
|
105
|
+
[
|
106
|
+
"http://example.com",
|
107
|
+
"https://example.org"
|
108
|
+
]
|
109
|
+
````
|
110
|
+
|
111
|
+
You can now upload the list.json url list to 80legs:
|
112
|
+
|
113
|
+
````ruby
|
114
|
+
file = File.read(/path/to/my/urls/list.json)
|
115
|
+
url = Leggy.urls.create(name: 'sample', body: file)
|
116
|
+
urls.name
|
117
|
+
#=> "sample"
|
118
|
+
````
|
119
|
+
|
120
|
+
#### Get All Url Lists
|
121
|
+
|
122
|
+
````ruby
|
123
|
+
urls = Leggy.urls.all
|
124
|
+
urls.collect(&:name)
|
125
|
+
#=> ["sample"]
|
126
|
+
````
|
127
|
+
|
128
|
+
#### Get Specific Url List
|
129
|
+
|
130
|
+
Given your list.json file uploaded previously includes http://example.com && http://example.org:
|
131
|
+
|
132
|
+
````ruby
|
133
|
+
Leggy.urls.find(name: 'sample')
|
134
|
+
#=> ["http://example.com", "https://example.org"]
|
135
|
+
````
|
136
|
+
|
137
|
+
#### Delete a Url List
|
138
|
+
|
139
|
+
*CAUTION* This action cannot be undone.
|
140
|
+
|
141
|
+
````ruby
|
142
|
+
Leggy.urls.delete(name: 'sample')
|
143
|
+
#=> true
|
144
|
+
````
|
145
|
+
|
146
|
+
### Crawls
|
147
|
+
|
148
|
+
See [http://datafiniti.github.io/80docs/?ruby#crawls](http://datafiniti.github.io/80docs/?ruby#crawls) for complete documentation.
|
149
|
+
|
150
|
+
#### View All Crawls
|
151
|
+
|
152
|
+
````ruby
|
153
|
+
crawls = Leggy.crawls.all
|
154
|
+
crawls.first.status
|
155
|
+
#=> "COMPLETED"
|
156
|
+
````
|
157
|
+
|
158
|
+
Querying by status is not yet available.
|
159
|
+
|
160
|
+
#### Create a Crawl
|
161
|
+
|
162
|
+
````ruby
|
163
|
+
options = {
|
164
|
+
name: 'crawl_test',
|
165
|
+
urllist: 'sample_crawl_list',
|
166
|
+
app: "HeaderData.js",
|
167
|
+
max_depth: 1,
|
168
|
+
max_urls: 10
|
169
|
+
}
|
170
|
+
Leggy.crawls.start(options)
|
171
|
+
#=> true
|
172
|
+
````
|
173
|
+
|
174
|
+
#### Get Crawl Status
|
175
|
+
|
176
|
+
````ruby
|
177
|
+
crawl = Leggy.crawls.status(name: 'crawl_test')
|
178
|
+
crawl.status
|
179
|
+
#=> "QUEUED"
|
180
|
+
````
|
181
|
+
|
182
|
+
#### Cancel a Crawl
|
183
|
+
|
184
|
+
````ruby
|
185
|
+
Leggy.crawls.cancel(name: 'crawl_test')
|
186
|
+
#=> true
|
187
|
+
````
|
188
|
+
|
189
|
+
Once cancelled, the crawl cannot be restarted.
|
190
|
+
|
191
|
+
### Results
|
192
|
+
|
193
|
+
See [http://datafiniti.github.io/80docs/?ruby#results](http://datafiniti.github.io/80docs/?ruby#results) for complete documentation.
|
194
|
+
|
195
|
+
#### View Results for a Crawl
|
196
|
+
|
197
|
+
````ruby
|
198
|
+
results = Leggy.results.all(name: 'testing_crawl_results')
|
199
|
+
results.first
|
200
|
+
#=> "http://datafiniti-voltron-results.s3.amazonaws.com/<TOKEN>/167627_1.txt"
|
201
|
+
````
|
202
|
+
|
203
|
+
### Errors
|
204
|
+
|
205
|
+
See [http://datafiniti.github.io/80docs/?ruby#errors](http://datafiniti.github.io/80docs/?ruby#errors) for complete documentation.
|
206
|
+
|
207
|
+
Leggy raises the following errors:
|
208
|
+
|
209
|
+
* 400 (Bad Request): `Leggy::Exception::BadRequest`
|
210
|
+
* 401 (Unauthorized): `Leggy::Exception::Unauthorized`
|
211
|
+
* 404 (Not Found): `Leggy::Exception::NotFound`
|
212
|
+
* 422 (Unprocessable Entity): `Leggy::Exception::UnprocessableEntity`
|
213
|
+
* 523 (Service Unavailable): `Leggy::Exception::ServiceUnavailable`
|
214
|
+
* 5xx (Server Error): `Leggy::Exception::ServerError`
|
215
|
+
|
216
|
+
All exceptions inherit from `Leggy::Error`, so you can use that rescue from any exceptions this client library raises. This does not take into account errors external dependencies may raise, such as Faraday or http adapter errors.
|
24
217
|
|
25
218
|
## Contributing
|
26
219
|
|
data/Rakefile
CHANGED
data/leggy.gemspec
CHANGED
@@ -27,11 +27,11 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "pry"
|
28
28
|
spec.add_development_dependency "dotenv"
|
29
29
|
|
30
|
-
spec.add_dependency "gem_config", "
|
30
|
+
spec.add_dependency "gem_config", "~> 0.3"
|
31
31
|
spec.add_dependency "faraday", "~> 0.9"
|
32
32
|
spec.add_dependency "faraday_middleware", "~> 0.9"
|
33
33
|
spec.add_dependency "resource_kit", "~> 0.1"
|
34
|
-
spec.add_dependency "kartograph", "
|
34
|
+
spec.add_dependency "kartograph", "~> 0.2"
|
35
35
|
spec.add_dependency "activesupport", "~> 4.0"
|
36
36
|
|
37
37
|
end
|
data/lib/leggy.rb
CHANGED
@@ -8,6 +8,8 @@ require "active_support/concern"
|
|
8
8
|
require "active_support/core_ext/hash/slice"
|
9
9
|
require "ostruct"
|
10
10
|
|
11
|
+
require "leggy/exceptions"
|
12
|
+
require "leggy/error_handler"
|
11
13
|
require "leggy/helpers"
|
12
14
|
require "leggy/user"
|
13
15
|
require "leggy/app"
|
@@ -23,12 +25,13 @@ require "leggy/resource/user"
|
|
23
25
|
require "leggy/resource/app"
|
24
26
|
require "leggy/resource/url"
|
25
27
|
require "leggy/resource/crawl"
|
28
|
+
require "leggy/resource/result"
|
26
29
|
|
27
30
|
module Leggy
|
28
31
|
include GemConfig::Base
|
29
32
|
|
30
33
|
with_configuration do
|
31
|
-
has :api_token,
|
34
|
+
has :api_token, classes: String, default: ENV['80_LEGS_API_TOKEN']
|
32
35
|
end
|
33
36
|
|
34
37
|
def self.api_token
|
@@ -40,7 +43,7 @@ module Leggy
|
|
40
43
|
end
|
41
44
|
|
42
45
|
def self.connection
|
43
|
-
|
46
|
+
Faraday.new(
|
44
47
|
url: 'https://api.80legs.com',
|
45
48
|
headers: {
|
46
49
|
content_type: 'application/json',
|
@@ -69,14 +72,20 @@ module Leggy
|
|
69
72
|
Leggy::Resource::Url.new(setup(options))
|
70
73
|
end
|
71
74
|
|
72
|
-
# This resource allows for the creation and cancelation of crawls.
|
73
|
-
# the user to view the crawl status and settings.
|
74
|
-
# links of the results will also be provided within the crawl.
|
75
|
+
# This resource allows for the creation and cancelation of crawls.
|
76
|
+
# It also allows the user to view the crawl status and settings.
|
75
77
|
#
|
76
78
|
def self.crawls(options = {})
|
77
79
|
Leggy::Resource::Crawl.new(setup(options))
|
78
80
|
end
|
79
81
|
|
82
|
+
# This resource allows for viewing a list of the urls containing
|
83
|
+
# the crawl results.
|
84
|
+
#
|
85
|
+
def self.results(options = {})
|
86
|
+
Leggy::Resource::Result.new(setup(options))
|
87
|
+
end
|
88
|
+
|
80
89
|
def self.setup(options)
|
81
90
|
options[:connection] = connection unless options[:connection]
|
82
91
|
options
|
data/lib/leggy/app.rb
CHANGED
data/lib/leggy/crawl.rb
CHANGED
data/lib/leggy/crawl_options.rb
CHANGED
data/lib/leggy/error.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Leggy
|
2
|
+
module ErrorHandler
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.send(:resources) do
|
6
|
+
|
7
|
+
default_handler do |response|
|
8
|
+
case response.status
|
9
|
+
when 200...299
|
10
|
+
next
|
11
|
+
when 400
|
12
|
+
raise Leggy::Exception::BadRequest.new("#{response.status}: #{response.body}")
|
13
|
+
when 401
|
14
|
+
raise Leggy::Exception::Unauthorized.new("#{response.status}: #{response.body}")
|
15
|
+
when 404
|
16
|
+
raise Leggy::Exception::NotFound.new("#{response.status}: #{response.body}")
|
17
|
+
when 422
|
18
|
+
raise Leggy::Exception::UnprocessableEntity.new("#{response.status}: #{response.body}")
|
19
|
+
when 523
|
20
|
+
raise Leggy::Exception::ServiceUnavailable.new("#{response.status}: #{response.body}")
|
21
|
+
else
|
22
|
+
raise Leggy::Exception::ServerError.new("#{response.status}: #{response.body}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# 400 Bad Request Often times a missing or incorrect parameter
|
2
|
+
# 401 Unauthorized Invalid/Missing API Token
|
3
|
+
# 404 Not Found Using an invalid API end point, or the user supplied path is incorrect
|
4
|
+
# 422 Unprocessable Entity All the parameters were correct but the request was rejected on the back end, contact support with request information
|
5
|
+
# 523 Service Unavailable The API is currently unavailable due to maitenance, try again later.
|
6
|
+
# 5xx Server Error There was an error within the Datafiniti servers
|
7
|
+
#
|
8
|
+
require 'leggy/error'
|
9
|
+
|
10
|
+
module Leggy
|
11
|
+
module Exception
|
12
|
+
class BadRequest < Leggy::Error
|
13
|
+
end
|
14
|
+
|
15
|
+
class Unauthorized < Leggy::Error
|
16
|
+
end
|
17
|
+
|
18
|
+
class NotFound < Leggy::Error
|
19
|
+
end
|
20
|
+
|
21
|
+
class UnprocessableEntity < Leggy::Error
|
22
|
+
end
|
23
|
+
|
24
|
+
class ServiceUnavailable < Leggy::Error
|
25
|
+
end
|
26
|
+
|
27
|
+
class ServerError < Leggy::Error
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/leggy/mapping/app.rb
CHANGED
@@ -6,13 +6,8 @@ module Leggy
|
|
6
6
|
kartograph do
|
7
7
|
mapping Leggy::App
|
8
8
|
|
9
|
-
property *Leggy::App.attr_accessors, scopes: :read
|
9
|
+
property *Leggy::App.attr_accessors, scopes: [ :read ]
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
15
|
-
# name string The name given to the app.
|
16
|
-
# user string The user the app is associated with.
|
17
|
-
# location string The internal location for the app.
|
18
|
-
# date_created date The date the app was uploaded.
|