captureapi 0.0.1

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.
@@ -0,0 +1,25 @@
1
+ # CaptureAPI
2
+
3
+ ## Rails3 Configuration
4
+
5
+ You will need to create an initializer before using the library.
6
+
7
+ Example:
8
+
9
+ ```ruby
10
+ # config/initializers/captureapi.rb
11
+ CaptureAPI.configure do |config|
12
+ config.api_key = '1a243b45c'
13
+ config.api_key_id = '3'
14
+ end
15
+ ```
16
+
17
+ ## View helpers
18
+
19
+ ### thumbnail_tag(url, options = {})
20
+
21
+ Valid options are:
22
+
23
+ `width`: The width of the final thumbnail (default: `200`).
24
+ `height`: The height of the final thumbnail (default: `200`).
25
+ `alt`: The value of the `alt` attribute for the `<img>` tag (default: `"Thumbnail of #{url}"`).
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ desc 'Bundle the gem'
6
+ task :bundle do
7
+ sh 'bundle install'
8
+ sh 'gem build *.gemspec'
9
+ sh 'gem install *.gem'
10
+ sh 'rm *.gem'
11
+ end
12
+
13
+ task(:default).clear
14
+ task :default => :bundle
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'captureapi/version'
3
+ require 'captureapi/configuration'
4
+ require 'captureapi/api'
5
+ require 'captureapi/railtie' if defined?(Rails::Railtie)
6
+
7
+ module CaptureAPI
8
+ class << self
9
+ # A CaptureAPI configuration object. Must act like a hash and return sensible
10
+ # values for all CaptureAPI configuration options. See CaptureAPI::Configuration
11
+ attr_writer :configuration
12
+
13
+ # Call this method to modify defaults in your initializers.
14
+ #
15
+ # @example
16
+ # CaptureAPI.configure do |config|
17
+ # config.api_key = '1a243b45c'
18
+ # config.api_key_id = '3'
19
+ # end
20
+ def configure
21
+ yield(configuration)
22
+ end
23
+
24
+ # The Configuration object.
25
+ # @see CaptureAPI.configure
26
+ def configuration
27
+ @configuration ||= Configuration.new
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ require 'uri'
2
+ require 'digest/sha2'
3
+ require 'time'
4
+
5
+ module CaptureAPI
6
+ module API
7
+ class << self
8
+ def thumbnail_uri(url, options = {})
9
+ configuration = CaptureAPI::configuration
10
+
11
+ options[:width] ||= 200
12
+ options[:height] ||= 200
13
+ options[:cache] ||= '1h'
14
+ options[:manipulations] ||= "thumbnail #{options[:width]} #{options[:height]}"
15
+
16
+ query = {
17
+ :url => url,
18
+ :key_id => configuration.api_key_id,
19
+ :cache => options[:cache],
20
+ :hash => request_hash(url),
21
+ :manipulations => options[:manipulations]
22
+ }
23
+
24
+ uri = URI::HTTP.build({
25
+ :host => configuration.host,
26
+ :path => '/inline_capture',
27
+ :query => query.to_query
28
+ })
29
+
30
+ uri.scheme = 'https'
31
+ uri
32
+ end
33
+
34
+ def request_hash(url)
35
+ configuration = CaptureAPI::configuration
36
+ api_key = configuration.api_key
37
+ date = Time.now.utc.strftime('%Y-%m-%d')
38
+ hash_data = "#{url}#{api_key}#{date}"
39
+ digest = Digest::SHA2.new(256)
40
+ digest.hexdigest(hash_data)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,19 @@
1
+ module CaptureAPI
2
+ # Used to set up and modify settings for the requests.
3
+ class Configuration
4
+ OPTIONS = [:api_key, :api_key_id, :host].freeze
5
+
6
+ # The API key for your user.
7
+ attr_accessor :api_key
8
+
9
+ # The API key id for your user.
10
+ attr_accessor :api_key_id
11
+
12
+ # The host to connect to (defaults to api.captureapi.com).
13
+ attr_accessor :host
14
+
15
+ def initialize
16
+ @host = 'api.captureapi.com'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ require 'captureapi/view_helpers'
2
+ module CaptureAPI
3
+ class Railtie < Rails::Railtie
4
+ initializer 'CaptureAPI.view_helpers' do
5
+ ActionView::Base.send :include, ViewHelpers
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module CaptureAPI
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,18 @@
1
+ module CaptureAPI
2
+ module ViewHelpers
3
+ def thumbnail_tag(url, options = {})
4
+ options.symbolize_keys!
5
+
6
+ options[:width] ||= 200
7
+ options[:height] ||= 200
8
+ options[:alt] ||= "Thumbnail of #{url}"
9
+
10
+ thumbnail_options = {
11
+ :width => options[:width],
12
+ :height => options[:height]
13
+ }
14
+
15
+ image_tag(CaptureAPI::API::thumbnail_uri(url, thumbnail_options), options)
16
+ end
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: captureapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - CaptureAPI
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-04 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: CaptureAPI provides view helpers for Rails 3.1 to easily integrate website
15
+ thumbnails into your web app.
16
+ email: webmaster@captureapi.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/captureapi/api.rb
22
+ - lib/captureapi/configuration.rb
23
+ - lib/captureapi/railtie.rb
24
+ - lib/captureapi/version.rb
25
+ - lib/captureapi/view_helpers.rb
26
+ - lib/captureapi.rb
27
+ - Rakefile
28
+ - README.md
29
+ homepage: http://captureapi.com
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.10
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Easily integrate website thumbnails into your web app.
53
+ test_files: []