capture_page 1.1.0 → 1.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/lib/capture.rb +30 -23
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3217118ed9497ccaaff219c4b5fd9345320790d99d88d252d14f363921832a4e
4
- data.tar.gz: 3c96668a060f2771e1210583c2e9aeb65fbf75b9d508d5f475c1fc4098cdd6f7
3
+ metadata.gz: ede382d29f59a4c71e609f79d74574122e2432a5d145873d8a038f5c4bf850f3
4
+ data.tar.gz: 6ad9064e2506f3bd2bada3d4025d894cf87be551272161627c472dcdf06a40c4
5
5
  SHA512:
6
- metadata.gz: cf1928267a630bc2f2e26cf5fc2db0443c995e523641f86ab8816038a52a5d388c0093973d3a33f97dbf5c509e6f054575cea7b2b5658575d46e96245338a1a8
7
- data.tar.gz: 3b62f1f2d90d24af537bd56fa87a1303eef91bb3e3e5355e2ac7a2e4027d797d46220ebf6a8c9bad97bde5440ac234497ce5e7b1441d651e5f94741bd109a1da
6
+ metadata.gz: 2f9ab18049ac143fe3aebd8b9c026705d5708c415743e639c3519b46ae30e6e9ffd4e69bb0af37b434849d350b3b86a407f2139bfa761778e26cc5ef9c99e0a9
7
+ data.tar.gz: c19f5374e91e3d332bc033684dfb25c3409dd8c7c14c199ada926a0f02b0b90fd61bfd58d6092d88b0c556aefdac88a3bba70d4dab656f1dc9cb5dbaa4b520ce
data/README.md CHANGED
@@ -136,13 +136,13 @@ File.binwrite("animation.gif", gif_data)
136
136
  ### Browser Sessions
137
137
 
138
138
  ```ruby
139
- session = client.create_session("maxTtlSeconds" => 300)
139
+ session = client.sessions.create("maxTtlSeconds" => 300)
140
140
  session_id = session["session"]["id"]
141
141
 
142
- client.execute_action(session_id, "goto", "url" => "https://example.com")
143
- screenshot = client.execute_action(session_id, "screenshot", "fullPage" => true)
142
+ client.sessions.action(session_id, "goto", "url" => "https://example.com")
143
+ screenshot = client.sessions.action(session_id, "screenshot", "fullPage" => true)
144
144
 
145
- client.close_session(session_id)
145
+ client.sessions.close(session_id)
146
146
  ```
147
147
 
148
148
  ## Configuration Options
data/lib/capture.rb CHANGED
@@ -16,11 +16,39 @@ class CaptureSessionsError < StandardError
16
16
  end
17
17
  end
18
18
 
19
+ class CaptureSessions
20
+ def initialize(client)
21
+ @client = client
22
+ end
23
+
24
+ def create(options = {})
25
+ options = options.nil? ? {} : options
26
+ raise TypeError, "options must be a Hash" unless options.is_a?(Hash)
27
+
28
+ @client.send(:sessions_request, "", :post, options)
29
+ end
30
+
31
+ def get(session_id)
32
+ @client.send(:sessions_request, "/#{@client.send(:escape_path, session_id)}", :get)
33
+ end
34
+
35
+ def close(session_id)
36
+ @client.send(:sessions_request, "/#{@client.send(:escape_path, session_id)}", :delete)
37
+ end
38
+
39
+ def action(session_id, action_type, payload = {})
40
+ payload = payload.nil? ? {} : payload
41
+ raise TypeError, "payload must be a Hash" unless payload.is_a?(Hash)
42
+
43
+ @client.send(:sessions_request, "/#{@client.send(:escape_path, session_id)}/actions", :post, "type" => action_type, "payload" => payload)
44
+ end
45
+ end
46
+
19
47
  class Capture
20
48
  API_URL = "https://cdn.capture.page"
21
49
  EDGE_URL = "https://edge.capture.page"
22
50
 
23
- attr_reader :key, :options
51
+ attr_reader :key, :options, :sessions
24
52
 
25
53
  def initialize(key, secret, options = {})
26
54
  @key = key
@@ -28,6 +56,7 @@ class Capture
28
56
  options = options.nil? ? {} : options
29
57
  raise TypeError, "options must be a Hash" unless options.is_a?(Hash)
30
58
  @options = options
59
+ @sessions = CaptureSessions.new(self)
31
60
  end
32
61
 
33
62
  def build_image_url(url, options = {})
@@ -70,28 +99,6 @@ class Capture
70
99
  fetch_binary(build_animated_url(url, options))
71
100
  end
72
101
 
73
- def create_session(options = {})
74
- options = options.nil? ? {} : options
75
- raise TypeError, "options must be a Hash" unless options.is_a?(Hash)
76
-
77
- sessions_request("", :post, options)
78
- end
79
-
80
- def get_session(session_id)
81
- sessions_request("/#{escape_path(session_id)}", :get)
82
- end
83
-
84
- def close_session(session_id)
85
- sessions_request("/#{escape_path(session_id)}", :delete)
86
- end
87
-
88
- def execute_action(session_id, action_type, payload = {})
89
- payload = payload.nil? ? {} : payload
90
- raise TypeError, "payload must be a Hash" unless payload.is_a?(Hash)
91
-
92
- sessions_request("/#{escape_path(session_id)}/actions", :post, "type" => action_type, "payload" => payload)
93
- end
94
-
95
102
  private
96
103
 
97
104
  def build_url(url, request_type, options)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capture_page
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Capture Team