leggy 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -0,0 +1,38 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://<TOKEN>:@api.80legs.com/v2/users/<TOKEN>
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- Faraday v0.9.2
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Date:
|
26
|
+
- Sat, 12 Dec 2015 06:03:33 GMT
|
27
|
+
Server:
|
28
|
+
- Cowboy
|
29
|
+
Content-Length:
|
30
|
+
- '328'
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
body:
|
34
|
+
encoding: UTF-8
|
35
|
+
string: '{"groups":"undefined","token":"<TOKEN>","organization":"Civvic","email":"mattsolt@gmail.com","first_name":"Matt","last_name":"Solt","phone_number":"undefined","stripe_customer_id":"cus_4lcSWy6GfXcdmE","plan_id":"basic","type":"user","active":1,"urls_crawled":0,"date_registered":"2014-4-22","groups":[]}'
|
36
|
+
http_version:
|
37
|
+
recorded_at: Sat, 12 Dec 2015 06:03:37 GMT
|
38
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Leggy::Exception, vcr: { cassette_name: 'leggy_exception', record: :none } do
|
4
|
+
|
5
|
+
context ".errors" do
|
6
|
+
|
7
|
+
before { Leggy.configuration.api_token = 'invalid' }
|
8
|
+
|
9
|
+
after { Leggy.configuration.reset }
|
10
|
+
|
11
|
+
it "raises a specific exception based on the error code" do
|
12
|
+
expect{
|
13
|
+
Leggy.crawls.all
|
14
|
+
}.to raise_error Leggy::Exception::Unauthorized
|
15
|
+
end
|
16
|
+
|
17
|
+
it "allows any exception to be rescued from Leggy::Error" do
|
18
|
+
expect{
|
19
|
+
Leggy.crawls.all
|
20
|
+
}.to raise_error Leggy::Error
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/spec/leggy/leggy_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Leggy
|
3
|
+
RSpec.describe Leggy do
|
4
4
|
|
5
5
|
before { Leggy.configuration.reset }
|
6
6
|
|
@@ -13,165 +13,4 @@ describe Leggy, vcr: { cassette_name: 'leggy' } do
|
|
13
13
|
expect(Leggy.api_token).to eq "MTIzNDo=\n"
|
14
14
|
end
|
15
15
|
|
16
|
-
context "Users" do
|
17
|
-
|
18
|
-
context "#find" do
|
19
|
-
|
20
|
-
it "returns a single user" do
|
21
|
-
user = Leggy.users.find(api_token: Leggy.configuration.api_token)
|
22
|
-
expect(user.first_name).to eq 'Matt'
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
context "Apps" do
|
30
|
-
|
31
|
-
context "#all" do
|
32
|
-
|
33
|
-
before(:each) { Leggy.apps.create(name: 'sample_all', body: fixture('sample_app.js')) }
|
34
|
-
after(:each) { Leggy.apps.delete(name: 'sample_all') }
|
35
|
-
|
36
|
-
it "returns a list of all apps" do
|
37
|
-
apps = Leggy.apps.all
|
38
|
-
expect(apps.collect(&:name)).to include 'sample_all'
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
context "#create" do
|
44
|
-
|
45
|
-
after(:each) { Leggy.apps.delete(name: 'sample') }
|
46
|
-
|
47
|
-
it "uploads a new app" do
|
48
|
-
app = Leggy.apps.create(name: 'sample', body: fixture('sample_app.js'))
|
49
|
-
expect(app).to be_truthy
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
context "#find" do
|
55
|
-
|
56
|
-
before(:each) { Leggy.apps.create(name: 'sample_find', body: fixture('sample_app.js')) }
|
57
|
-
after(:each) { Leggy.apps.delete(name: 'sample_find') }
|
58
|
-
|
59
|
-
it "returns a single app" do
|
60
|
-
app = Leggy.apps.find(name: 'sample_find')
|
61
|
-
expect(app).to match /\A\/\//
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
context "#delete" do
|
67
|
-
|
68
|
-
before(:each) { Leggy.apps.create(name: 'sample_delete', body: fixture('sample_app.js')) }
|
69
|
-
|
70
|
-
it "removes an app" do
|
71
|
-
app = Leggy.apps.delete(name: 'sample_delete')
|
72
|
-
expect(app).to be_truthy
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
context "Urls" do
|
80
|
-
|
81
|
-
context "#all" do
|
82
|
-
|
83
|
-
before(:each) { Leggy.urls.create(name: 'sample_all', body: fixture('urls.json')) }
|
84
|
-
after(:each) { Leggy.urls.delete(name: 'sample_all') }
|
85
|
-
|
86
|
-
it "returns a list of all url lists" do
|
87
|
-
urls = Leggy.urls.all
|
88
|
-
expect(urls.collect(&:name)).to include 'sample_all'
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
context "#create" do
|
94
|
-
|
95
|
-
after(:each) { Leggy.urls.delete(name: 'sample') }
|
96
|
-
|
97
|
-
it "uploads a new url list" do
|
98
|
-
url = Leggy.urls.create(name: 'sample', body: fixture('urls.json'))
|
99
|
-
expect(url).to be_truthy
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
context "#find" do
|
105
|
-
|
106
|
-
before(:each) { Leggy.urls.create(name: 'sample_find', body: fixture('urls.json')) }
|
107
|
-
after(:each) { Leggy.urls.delete(name: 'sample_find') }
|
108
|
-
|
109
|
-
it "returns a single url list" do
|
110
|
-
url = Leggy.urls.find(name: 'sample_find')
|
111
|
-
expect(url).to include 'http://example.com'
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
context "#delete" do
|
117
|
-
|
118
|
-
before(:each) { Leggy.urls.create(name: 'sample_delete', body: fixture('urls.json')) }
|
119
|
-
|
120
|
-
it "removes an url list" do
|
121
|
-
url = Leggy.urls.delete(name: 'sample_delete')
|
122
|
-
expect(url).to be_truthy
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
context "Urls" do
|
130
|
-
|
131
|
-
let(:options) do
|
132
|
-
{
|
133
|
-
name: "start_crawl",
|
134
|
-
app: "HeaderData.js",
|
135
|
-
urllist: "1",
|
136
|
-
max_depth: 2,
|
137
|
-
max_urls: 1000
|
138
|
-
}
|
139
|
-
end
|
140
|
-
|
141
|
-
context "#start" do
|
142
|
-
|
143
|
-
after(:each) { Leggy.crawls.cancel(name: "start_crawl") }
|
144
|
-
|
145
|
-
it "starts a new crawl" do
|
146
|
-
crawl = Leggy.crawls.start(options)
|
147
|
-
expect(crawl).to be_truthy
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
context "#status" do
|
153
|
-
|
154
|
-
before(:each) { Leggy.crawls.start(options.merge(name: "status_crawl")) }
|
155
|
-
after(:each) { Leggy.crawls.cancel(name: "status_crawl") }
|
156
|
-
|
157
|
-
it "uploads a new url list" do
|
158
|
-
crawl = Leggy.crawls.status(name: "status_crawl")
|
159
|
-
expect(crawl.status).to eq 'QUEUED'
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
context "#cancel" do
|
165
|
-
|
166
|
-
before(:each) { Leggy.crawls.start(options.merge(name: "cancel_crawl")) }
|
167
|
-
|
168
|
-
it "returns a single url list" do
|
169
|
-
crawl = Leggy.crawls.cancel(name: "cancel_crawl")
|
170
|
-
expect(crawl).to be_truthy
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|
174
|
-
|
175
|
-
end
|
176
|
-
|
177
16
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Leggy::Resource::App, vcr: { cassette_name: 'leggy_app', record: :none } do
|
4
|
+
|
5
|
+
it "includes Leggy::ErrorHandler" do
|
6
|
+
expect(described_class.ancestors).to include Leggy::ErrorHandler
|
7
|
+
end
|
8
|
+
|
9
|
+
context ".apps" do
|
10
|
+
|
11
|
+
context ".all" do
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
Leggy.apps.create(name: 'sample_all', body: fixture('sample_app.js'))
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:each) do
|
18
|
+
Leggy.apps.delete(name: 'sample_all')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns a list of all apps" do
|
22
|
+
apps = Leggy.apps.all
|
23
|
+
expect(apps.collect(&:name)).to include 'sample_all'
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
context ".create" do
|
29
|
+
|
30
|
+
after(:each) { Leggy.apps.delete(name: 'sample') }
|
31
|
+
|
32
|
+
it "uploads a new app" do
|
33
|
+
app = Leggy.apps.create(name: 'sample', body: fixture('sample_app.js'))
|
34
|
+
expect(app).to be_truthy
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context ".find" do
|
40
|
+
|
41
|
+
before(:each) { Leggy.apps.create(name: 'sample_find', body: fixture('sample_app.js')) }
|
42
|
+
after(:each) { Leggy.apps.delete(name: 'sample_find') }
|
43
|
+
|
44
|
+
it "returns a single app" do
|
45
|
+
app = Leggy.apps.find(name: 'sample_find')
|
46
|
+
expect(app).to match /\A\/\//
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context ".delete" do
|
52
|
+
|
53
|
+
before(:each) { Leggy.apps.create(name: 'sample_delete', body: fixture('sample_app.js')) }
|
54
|
+
|
55
|
+
it "removes an app" do
|
56
|
+
app = Leggy.apps.delete(name: 'sample_delete')
|
57
|
+
expect(app).to be_truthy
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Leggy::Resource::Crawl do
|
4
|
+
|
5
|
+
it "includes Leggy::ErrorHandler" do
|
6
|
+
expect(described_class.ancestors).to include Leggy::ErrorHandler
|
7
|
+
end
|
8
|
+
|
9
|
+
context ".crawls" do
|
10
|
+
|
11
|
+
let(:options) do
|
12
|
+
{
|
13
|
+
app: "HeaderData.js",
|
14
|
+
max_depth: 1,
|
15
|
+
max_urls: 10
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
context ".all", vcr: { cassette_name: 'leggy_crawl_all', record: :none } do
|
20
|
+
|
21
|
+
it "returns a list of all crawls" do
|
22
|
+
crawls = Leggy.crawls.all
|
23
|
+
expect(crawls).not_to be_empty
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
context ".start", vcr: { cassette_name: 'leggy_crawl_start', record: :none } do
|
29
|
+
|
30
|
+
before do
|
31
|
+
options.merge!(name: 'testing_crawl_start', urllist: 'sample_crawl_list')
|
32
|
+
Leggy.urls.create(name: 'sample_crawl_list', body: fixture('urls.json'))
|
33
|
+
end
|
34
|
+
|
35
|
+
after do
|
36
|
+
Leggy.urls.delete(name: 'sample_crawl_list')
|
37
|
+
Leggy.crawls.cancel(name: 'testing_crawl_start')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "starts a new crawl" do
|
41
|
+
crawl = Leggy.crawls.start(options)
|
42
|
+
expect(crawl).to be_truthy
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
context ".status", vcr: { cassette_name: 'leggy_crawl_status', record: :none } do
|
48
|
+
|
49
|
+
before do
|
50
|
+
options.merge!(name: 'testing_crawl_status', urllist: 'sample_crawl_list')
|
51
|
+
Leggy.urls.create(name: 'sample_crawl_list', body: fixture('urls.json'))
|
52
|
+
Leggy.crawls.start(options)
|
53
|
+
end
|
54
|
+
|
55
|
+
after do
|
56
|
+
Leggy.urls.delete(name: 'sample_crawl_list')
|
57
|
+
Leggy.crawls.cancel(name: 'testing_crawl_status')
|
58
|
+
end
|
59
|
+
|
60
|
+
it "uploads a new url list" do
|
61
|
+
crawl = Leggy.crawls.status(name: "testing_crawl_status")
|
62
|
+
expect(crawl.status).to match /QUEUED|STARTED/
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context ".cancel", vcr: { cassette_name: 'leggy_crawl_cancel', record: :none } do
|
68
|
+
|
69
|
+
before do
|
70
|
+
options.merge!(name: 'testing_crawl_cancel', urllist: 'sample_crawl_list')
|
71
|
+
Leggy.urls.create(name: 'sample_crawl_list', body: fixture('urls.json'))
|
72
|
+
Leggy.crawls.start(options)
|
73
|
+
end
|
74
|
+
|
75
|
+
after do
|
76
|
+
Leggy.urls.delete(name: 'sample_crawl_list')
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns a single url list" do
|
80
|
+
crawl = Leggy.crawls.cancel(name: 'testing_crawl_cancel')
|
81
|
+
expect(crawl).to be_truthy
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Leggy::Resource::Result do
|
4
|
+
|
5
|
+
it "includes Leggy::ErrorHandler" do
|
6
|
+
expect(described_class.ancestors).to include Leggy::ErrorHandler
|
7
|
+
end
|
8
|
+
|
9
|
+
context ".results" do
|
10
|
+
|
11
|
+
let(:options) do
|
12
|
+
{
|
13
|
+
app: "HeaderData.js",
|
14
|
+
max_depth: 1,
|
15
|
+
max_urls: 10
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
# If rerunning this test without a cassette, it needs to be run in stages
|
20
|
+
# to allow for the crawl to finish and generate results
|
21
|
+
#
|
22
|
+
context ".all", vcr: { cassette_name: 'leggy_result', record: :none } do
|
23
|
+
|
24
|
+
before do
|
25
|
+
options.merge!(name: 'testing_crawl_results', urllist: 'sample_crawl_list')
|
26
|
+
Leggy.urls.create(name: 'sample_crawl_list', body: fixture('urls.json'))
|
27
|
+
Leggy.crawls.start(options)
|
28
|
+
end
|
29
|
+
|
30
|
+
after do
|
31
|
+
Leggy.urls.delete(name: 'sample_crawl_list')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns the s3 url of the results download" do
|
35
|
+
results = Leggy.results.all(name: 'testing_crawl_results')
|
36
|
+
expect(results.count).to be > 0
|
37
|
+
results.each do |result|
|
38
|
+
expect(result).to match Regexp.new(Regexp.escape("s3.amazonaws.com"))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Leggy::Resource::Url, vcr: { cassette_name: 'leggy_url', record: :none } do
|
4
|
+
|
5
|
+
it "includes Leggy::ErrorHandler" do
|
6
|
+
expect(described_class.ancestors).to include Leggy::ErrorHandler
|
7
|
+
end
|
8
|
+
|
9
|
+
context ".urls" do
|
10
|
+
|
11
|
+
context ".all" do
|
12
|
+
|
13
|
+
before(:each) { Leggy.urls.create(name: 'sample_all', body: fixture('urls.json')) }
|
14
|
+
after(:each) { Leggy.urls.delete(name: 'sample_all') }
|
15
|
+
|
16
|
+
it "returns a list of all url lists" do
|
17
|
+
urls = Leggy.urls.all
|
18
|
+
expect(urls.collect(&:name)).to include 'sample_all'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context ".create" do
|
24
|
+
|
25
|
+
after(:each) { Leggy.urls.delete(name: 'sample') }
|
26
|
+
|
27
|
+
it "uploads a new url list" do
|
28
|
+
url = Leggy.urls.create(name: 'sample', body: fixture('urls.json'))
|
29
|
+
expect(url).to be_truthy
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context ".find" do
|
35
|
+
|
36
|
+
before(:each) { Leggy.urls.create(name: 'sample_find', body: fixture('urls.json')) }
|
37
|
+
after(:each) { Leggy.urls.delete(name: 'sample_find') }
|
38
|
+
|
39
|
+
it "returns a single url list" do
|
40
|
+
url = Leggy.urls.find(name: 'sample_find')
|
41
|
+
expect(url).to include 'http://example.com'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
context ".delete" do
|
47
|
+
|
48
|
+
before(:each) { Leggy.urls.create(name: 'sample_delete', body: fixture('urls.json')) }
|
49
|
+
|
50
|
+
it "removes an url list" do
|
51
|
+
url = Leggy.urls.delete(name: 'sample_delete')
|
52
|
+
expect(url).to be_truthy
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|