url_to_png 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 67621d2d06d46ea654e628225b482d6f0bda228f
4
+ data.tar.gz: 79f43fdcb2f2a172e4089b3ef080a32eebaeb518
5
+ SHA512:
6
+ metadata.gz: e9a32817f258dff28e8da81362ad393828d01955c5195aaddc81eb571695e07f0eb4a2a494afa116aaf246e8cf9c8edc1cfc1f9eac151c5f6bda798e8cab8e29
7
+ data.tar.gz: 36c7ed35479befe3fa38918abe8e05bc34ea49783c221bc7924f45f37ee643dac962d210e25db8881c55656458528c80bf16c1f0ea119669f6782bd06316db64
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in url_to_png.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Isaac Cambron
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # UrlToPng
2
+
3
+ A simple, Faraday-extensible library for accessing the [url2png](https://url2png.com) JSON API.
4
+
5
+ ## Installation
6
+
7
+ gem 'url_to_png'
8
+
9
+ ## Usage
10
+
11
+ ```rb
12
+ UrlToPng.configure do |config|
13
+ config.api_key = "XXXX"
14
+ config.secret_key = "XXXX"
15
+ end
16
+
17
+ UrlToPng.convert("http://google.com", viewport: "1024x800") #=> a Hashie::Mash
18
+ ```
19
+
20
+ There are all kinds of options, and you can use your own Faraday middleware. I'm sure I'll get around to documenting it.
21
+
22
+ ## Tests
23
+
24
+ There are none! This is not like some philisophical thing; it's just that I didn't bother. So maybe all kinds of things are broken. Who knows?
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,44 @@
1
+ require 'digest'
2
+ require 'addressable/uri'
3
+ require 'faraday_middleware'
4
+
5
+ require 'url_to_png/result'
6
+
7
+ module UrlToPng
8
+ class Client
9
+
10
+ def initialize(inopts = Configuration.new)
11
+ @options = defaults.merge(UrlToPng.configuration).merge(inopts)
12
+
13
+ raise "Need to provide an API key and secret" unless @options.configured?
14
+ end
15
+
16
+ def middleware
17
+ connection.builder
18
+ end
19
+
20
+ def convert(url)
21
+ uri = Addressable::URI.new(query_values: @options.query_hash.merge(url: url))
22
+ token = Digest::MD5.hexdigest(uri.query + @options.secret_key)
23
+ uri.path = "/v6/#{@options.api_key}/#{token}/json/"
24
+
25
+ response = connection.get(uri.to_s)
26
+ return Result.new(response.body)
27
+ end
28
+
29
+ private
30
+
31
+
32
+ def defaults
33
+ Configuration.from(base_url: 'api.url2png.com')
34
+ end
35
+
36
+ def connection
37
+ @connection ||= Faraday.new("http://#{@options.base_url}", @options.connection) do |builder|
38
+ builder.adapter :net_http
39
+ builder.response :json, content_type: /\bjson$/
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,47 @@
1
+ require 'faraday'
2
+
3
+ module UrlToPng
4
+ class Configuration < Faraday::Options.new(
5
+ :api_key,
6
+ :base_url,
7
+ :connection,
8
+ :custom_css,
9
+ :fullpage,
10
+ :say_cheese,
11
+ :secret_key,
12
+ :thumbnail_max_width,
13
+ :unique,
14
+ :user_agent,
15
+ :viewport
16
+ )
17
+
18
+ QUERY_OPTIONS = [
19
+ :custom_css,
20
+ :fullpage,
21
+ :say_cheese,
22
+ :thumbnail_max_width,
23
+ :unique,
24
+ :user_agent,
25
+ :viewport
26
+ ]
27
+
28
+ options connection: Faraday::ConnectionOptions
29
+
30
+ memoized(:connection) { self.class.options_for(:connection).new }
31
+
32
+ def configured?
33
+ !api_key.nil? && !secret_key.nil?
34
+ end
35
+
36
+ def query_hash
37
+ QUERY_OPTIONS.inject({}) do |hash, item|
38
+ value = send(item)
39
+ if (value)
40
+ hash[item] = send(item)
41
+ end
42
+ hash
43
+ end
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,12 @@
1
+ require 'hashie'
2
+
3
+ module UrlToPng
4
+ class Result < Hashie::Mash
5
+
6
+ def initialize(hash)
7
+ hash.delete("_disclaimer_")
8
+ super(hash)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module UrlToPng
2
+ VERSION = "0.0.1"
3
+ end
data/lib/url_to_png.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "url_to_png/version"
2
+ require "url_to_png/client"
3
+ require "url_to_png/configuration"
4
+
5
+ module UrlToPng
6
+ def self.configuration
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def self.configure
11
+ yield configuration
12
+ end
13
+
14
+ def self.convert(url, options = {})
15
+ Client.new(options).convert(url)
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'url_to_png/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "url_to_png"
8
+ spec.version = UrlToPng::VERSION
9
+ spec.authors = ["Isaac Cambron"]
10
+ spec.email = ["isaac@isaaccambron.com"]
11
+ spec.summary = "Client library for url2png"
12
+ spec.homepage = "http://github.com/icambron/url_to_png"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'faraday'
21
+ spec.add_dependency 'faraday_middleware'
22
+ spec.add_dependency 'hashie'
23
+
24
+ spec.add_dependency 'json'
25
+ spec.add_dependency 'addressable'
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.6"
28
+ spec.add_development_dependency "rake"
29
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: url_to_png
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Isaac Cambron
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: addressable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - isaac@isaaccambron.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - lib/url_to_png.rb
124
+ - lib/url_to_png/client.rb
125
+ - lib/url_to_png/configuration.rb
126
+ - lib/url_to_png/result.rb
127
+ - lib/url_to_png/version.rb
128
+ - url_to_png.gemspec
129
+ homepage: http://github.com/icambron/url_to_png
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.2.2
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Client library for url2png
153
+ test_files: []