grabz_it 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +105 -2
- data/lib/grabz_it/client.rb +21 -8
- data/lib/grabz_it/cookie.rb +36 -0
- data/lib/grabz_it/version.rb +1 -1
- data/spec/client_spec.rb +3 -3
- metadata +1 -1
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# GrabzIt
|
2
2
|
|
3
|
-
|
3
|
+
Interfaces with the GrabzIt screenshot service (http://grabz.it)
|
4
|
+
|
5
|
+
Yard docs can be found at http://www.rubydoc.info/github/cavneb/grabz_it/master/frames
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -15,10 +17,111 @@ And then execute:
|
|
15
17
|
Or install it yourself as:
|
16
18
|
|
17
19
|
$ gem install grabz_it
|
20
|
+
|
21
|
+
## Dependencies
|
22
|
+
* [rspec](https://github.com/rspec/rspec) (used in tests only)
|
18
23
|
|
19
24
|
## Usage
|
20
25
|
|
21
|
-
|
26
|
+
### Save Picture
|
27
|
+
|
28
|
+
Calls the GrabzIt web service to take the screenshot and saves it to the target path provided.
|
29
|
+
|
30
|
+
*Warning, this is a SYNCHONOUS method and can take up to 5 minutes before a response.*
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
client = GrabzIt::Client.new('TEST_KEY', 'TEST_SECRET')
|
34
|
+
options = {
|
35
|
+
:url => 'http://grabz.it',
|
36
|
+
:callback_url => 'http://example.com/callback',
|
37
|
+
:browser_width => 1024,
|
38
|
+
:browser_height => 768,
|
39
|
+
:output_width => 800,
|
40
|
+
:output_height => 600,
|
41
|
+
:custom_id => '12345',
|
42
|
+
:format => 'png',
|
43
|
+
:delay => 1000
|
44
|
+
}
|
45
|
+
client.save_picture('/tmp/my_picture.png', options)
|
46
|
+
|
47
|
+
puts File.exists?('/tmp/my_picture.png')
|
48
|
+
# => true
|
49
|
+
```
|
50
|
+
|
51
|
+
### Take Picture
|
52
|
+
|
53
|
+
Calls the GrabzIt web service to take the screenshot. It will optionally ping a callback url with the custom id if provided.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
client = GrabzIt::Client.new('TEST_KEY', 'TEST_SECRET')
|
57
|
+
options = {
|
58
|
+
:url => 'http://grabz.it',
|
59
|
+
:callback_url => 'http://example.com/callback',
|
60
|
+
:browser_width => 1024,
|
61
|
+
:browser_height => 768,
|
62
|
+
:output_width => 800,
|
63
|
+
:output_height => 600,
|
64
|
+
:custom_id => '12345',
|
65
|
+
:format => 'png',
|
66
|
+
:delay => 1000
|
67
|
+
}
|
68
|
+
response = client.take_picture('google', options)
|
69
|
+
|
70
|
+
puts response.screenshot_id
|
71
|
+
# => 'Y2F2bmViQGdtYWlsLmNvbQ==-20943258e37c4fc28c4977cd76c40f58'
|
72
|
+
```
|
73
|
+
|
74
|
+
### Get Picture
|
75
|
+
|
76
|
+
Get the screenshot image
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
client = GrabzIt::Client.new('TEST_KEY', 'TEST_SECRET')
|
80
|
+
image = client.get_image('Y2F2bmViQGdtYWlsLmNvbQ==-20943258e37c4fc28c4977cd76c40f58')
|
81
|
+
|
82
|
+
puts image.content_type
|
83
|
+
# => 'image/png'
|
84
|
+
puts image.size
|
85
|
+
# => 129347
|
86
|
+
|
87
|
+
image.save("/tmp/myimage.png")
|
88
|
+
File.exist?("/tmp/myimage.png")
|
89
|
+
# => true
|
90
|
+
```
|
91
|
+
|
92
|
+
### Get Status
|
93
|
+
|
94
|
+
Get the current status of a GrabzIt screenshot.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
client = GrabzIt::Client.new('TEST_KEY', 'TEST_SECRET')
|
98
|
+
status = client.get_status('Y2F2bmViQGdtYWlsLmNvbQ==-20943258e37c4fc28c4977cd76c40f58')
|
99
|
+
|
100
|
+
puts status.failed?
|
101
|
+
# => false
|
102
|
+
puts status.available?
|
103
|
+
# => true
|
104
|
+
```
|
105
|
+
|
106
|
+
### Get Cookie Jar
|
107
|
+
|
108
|
+
Get all the cookies that GrabzIt is using for a particular domain. This may include your user set cookies as well.
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
client = GrabzIt::Client.new('TEST_KEY', 'TEST_SECRET')
|
112
|
+
cookie_jar = client.get_cookie_jar('google')
|
113
|
+
|
114
|
+
puts cookie_jar.cookies.count
|
115
|
+
# => 3
|
116
|
+
puts cookie_jar.cookies[0].name
|
117
|
+
# => 'secure'
|
118
|
+
puts cookie_jar.cookies[0].domain
|
119
|
+
# => 'accounts.google.com'
|
120
|
+
```
|
121
|
+
|
122
|
+
## TODO
|
123
|
+
|
124
|
+
* Create the ability to set and delete cookies.
|
22
125
|
|
23
126
|
## Contributing
|
24
127
|
|
data/lib/grabz_it/client.rb
CHANGED
@@ -20,8 +20,8 @@ module GrabzIt
|
|
20
20
|
end
|
21
21
|
|
22
22
|
##
|
23
|
-
# Calls the GrabzIt web service to take the screenshot. Warning, this is a
|
24
|
-
# 5 minutes before a response.
|
23
|
+
# Calls the GrabzIt web service to take the screenshot and saves it to the target path provided. Warning, this is a
|
24
|
+
# SYNCHONOUS method and can take up to 5 minutes before a response.
|
25
25
|
#
|
26
26
|
# @param [String] target_path File path that the file should be saved to (including file name and extension)
|
27
27
|
# @param [Hash] options Data that is to be passed to the web service
|
@@ -50,7 +50,7 @@ module GrabzIt
|
|
50
50
|
# :format => 'png',
|
51
51
|
# :delay => 1000
|
52
52
|
# }
|
53
|
-
# response = client.
|
53
|
+
# response = client.save_picture('google', options)
|
54
54
|
#
|
55
55
|
def save_picture(target_path, options = {})
|
56
56
|
response = take_picture(options)
|
@@ -140,17 +140,17 @@ module GrabzIt
|
|
140
140
|
end
|
141
141
|
|
142
142
|
##
|
143
|
-
# Get the
|
143
|
+
# Get all the cookies that GrabzIt is using for a particular domain. This may include your user set cookies as well.
|
144
144
|
#
|
145
|
-
# @param [String]
|
145
|
+
# @param [String] domain The domain of the cookie
|
146
146
|
#
|
147
|
-
# @return [GrabzIt::
|
147
|
+
# @return [GrabzIt::CookieJar] The container that holds the cookies
|
148
148
|
#
|
149
149
|
# @example
|
150
150
|
# client = GrabzIt::Client.new('TEST_KEY', 'TEST_SECRET')
|
151
|
-
#
|
151
|
+
# cookie_jar = client.get_cookie_jar('google')
|
152
152
|
#
|
153
|
-
def
|
153
|
+
def get_cookie_jar(domain)
|
154
154
|
action = "getcookies.ashx"
|
155
155
|
sig = Digest::MD5.hexdigest(@app_secret + "|" + domain)
|
156
156
|
params = {
|
@@ -164,6 +164,18 @@ module GrabzIt
|
|
164
164
|
cookie_jar
|
165
165
|
end
|
166
166
|
|
167
|
+
##
|
168
|
+
# Pending API documentation
|
169
|
+
#
|
170
|
+
# def set_cookie(options = {})
|
171
|
+
# end
|
172
|
+
|
173
|
+
##
|
174
|
+
# Pending API documentation
|
175
|
+
#
|
176
|
+
# def delete_cookie(name, domain)
|
177
|
+
# end
|
178
|
+
|
167
179
|
##
|
168
180
|
# Get the screenshot image
|
169
181
|
#
|
@@ -193,6 +205,7 @@ module GrabzIt
|
|
193
205
|
|
194
206
|
# Helper method that performs the request
|
195
207
|
def query_api(action, params)
|
208
|
+
params = params.symbolize_keys
|
196
209
|
uri = URI("#{API_BASE_URL}#{action}")
|
197
210
|
uri.query = URI.encode_www_form(params)
|
198
211
|
res = Net::HTTP.get_response(uri)
|
data/lib/grabz_it/cookie.rb
CHANGED
@@ -1,5 +1,41 @@
|
|
1
1
|
module GrabzIt
|
2
2
|
class Cookie
|
3
3
|
attr_accessor :name, :value, :domain, :path, :http_only, :expires, :type
|
4
|
+
|
5
|
+
# def initialize(options = {})
|
6
|
+
# options = options.symbolize_keys
|
7
|
+
# @domain = options[:domain]
|
8
|
+
# @name = options[:name]
|
9
|
+
# @value = options[:value]
|
10
|
+
# @path = options[:path]
|
11
|
+
# @http_only = options[:http_only]
|
12
|
+
# @expires = options[:expires]
|
13
|
+
# end
|
14
|
+
|
15
|
+
# def params_for_set_request
|
16
|
+
# {
|
17
|
+
# :domain => URI.escape(@domain) || '',
|
18
|
+
# :name => URI.escape(@name) || '',
|
19
|
+
# :value => URI.escape(@value) || '',
|
20
|
+
# :path => URI.escape(@path) || '',
|
21
|
+
# :http_only => @http_only ? 1 : 0,
|
22
|
+
# :expires => URI.escape(@expires) || ''
|
23
|
+
# }
|
24
|
+
# end
|
25
|
+
|
26
|
+
# def generate_signature(app_key)
|
27
|
+
# parts = []
|
28
|
+
# parts << app_key
|
29
|
+
# parts << @name
|
30
|
+
# parts << @domain
|
31
|
+
# parts << @value
|
32
|
+
# parts << @path
|
33
|
+
# parts << @http_only ? 1 : 0
|
34
|
+
# parts << @expires
|
35
|
+
# parts << 0
|
36
|
+
# unencoded_sig = parts.join('|')
|
37
|
+
# puts "SIG: #{unencoded_sig}"
|
38
|
+
# sig = Digest::MD5.hexdigest(unencoded_sig)
|
39
|
+
# end
|
4
40
|
end
|
5
41
|
end
|
data/lib/grabz_it/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -127,7 +127,7 @@ describe GrabzIt::Client do
|
|
127
127
|
## ------------------------------------------------------------------------------------
|
128
128
|
# Get Cookies
|
129
129
|
## ------------------------------------------------------------------------------------
|
130
|
-
describe "#
|
130
|
+
describe "#get_cookie_jar" do
|
131
131
|
it "with valid domain" do
|
132
132
|
xml = <<-EOF
|
133
133
|
<?xml version="1.0"?>
|
@@ -164,7 +164,7 @@ describe GrabzIt::Client do
|
|
164
164
|
</WebResult>
|
165
165
|
EOF
|
166
166
|
@client.stub!(:query_api).and_return(xml)
|
167
|
-
cookie_jar = @client.
|
167
|
+
cookie_jar = @client.get_cookie_jar('google')
|
168
168
|
cookie_jar.cookies.size.should eq(3)
|
169
169
|
cookie_jar.cookies[0].name.should eq('secure')
|
170
170
|
cookie_jar.cookies[0].domain.should eq('accounts.google.com')
|
@@ -179,7 +179,7 @@ describe GrabzIt::Client do
|
|
179
179
|
</WebResult>
|
180
180
|
EOF
|
181
181
|
@client.stub!(:query_api).and_return(xml)
|
182
|
-
cookie_jar = @client.
|
182
|
+
cookie_jar = @client.get_cookie_jar('fsoi')
|
183
183
|
cookie_jar.cookies.should be_empty
|
184
184
|
end
|
185
185
|
end
|