infogram 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 06d4d238d852eaad9bf81cb702b933f72048113b
4
+ data.tar.gz: d2db6c1127370ee6c6c915677a35d311371201a2
5
+ SHA512:
6
+ metadata.gz: 934617a4f0bfa4678fe31e63c9fbc16f330610b74823ebdf230bce593a5c5fed2a250049441d16e7cf594513216c32b75d7696734b011b5a767b1534a23354fc
7
+ data.tar.gz: 099841292e7646ebf8e30848814e9b94ee9a74b9ac50f95910ec15fc2efe0161cca355568270b6b014ab3cec428e7681f9e5ec3d377b38df9a07764c9291e92a
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *~
2
+ .*
3
+ pkg/*
4
+ doc/*
5
+ Gemfile.lock
6
+ *.gem
7
+ docs/_build
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'pry'
5
+ gem 'pry-stack_explorer'
6
+ gem 'redcarpet'
7
+ end
8
+
9
+ group :test do
10
+ gem 'rspec'
11
+ gem 'guard-rspec'
12
+ gem 'webmock'
13
+ end
14
+
15
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,4 @@
1
+ guard 'rspec', cmd: 'bundle exec rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Maksim Berjoza
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,59 @@
1
+ # Infogram::Ruby
2
+
3
+ Ruby library for Infogr.am
4
+
5
+ ## Installation
6
+
7
+ $ gem install infogram
8
+
9
+ ## Usage
10
+ ```ruby
11
+ require 'infogram'
12
+
13
+ client = Infogram.new('API_KEY', 'API_SECRET')
14
+ infogram.themes.list
15
+ ```
16
+
17
+ ## Example response
18
+ ```json
19
+ [
20
+ {
21
+ "id": 61,
22
+ "title": "twitter",
23
+ "thumb": "https://infogr.am/i/templates/61/twitter-thumbnail-small.png"
24
+ },
25
+ {
26
+ "id": 44,
27
+ "title": "Megaphone",
28
+ "thumb": "https://infogr.am/i/templates/S/PRO-megaphone.png"
29
+ },
30
+ {
31
+ "id": 34,
32
+ "title": "Asketic-new",
33
+ "thumb": "https://infogr.am/i/templates/S/asketic-black.png"
34
+ }
35
+ ]
36
+ ```
37
+
38
+ ## API Methods
39
+
40
+ ### Themes
41
+ `client.themes.list`
42
+
43
+ ### Infograraphics
44
+ `client.infographics.list`
45
+ `client.infographics.get(infographic_id)`
46
+ `client.infographics.create(params)`
47
+ `client.infographics.update(infographic_id, params)`
48
+ `client.infographics.destroy(infographic_id)`
49
+
50
+ ### Users
51
+ `client.users.list.get_infographics(user_id)`
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/[my-github-username]/infogram-ruby/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/infogram.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'infogram/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'infogram'
7
+ s.version = Infogram::VERSION
8
+ s.authors = ['Maksim Berjoza']
9
+ s.email = ['torbjon@gmail.com']
10
+ s.summary = 'Infogr.am Ruby SDK'
11
+ s.description = 'Ruby library for Infogr.am'
12
+ s.homepage = 'https://github.com/infogram/infogram-ruby'
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files -x Gemfile.lock`.split("\n") rescue ''
16
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
+ s.require_paths = ['lib']
18
+
19
+ s.add_development_dependency 'bundler', '~> 1.7'
20
+ s.add_development_dependency 'rake', '~> 10.0'
21
+ s.add_dependency 'httparty', '~> 0.13'
22
+ s.add_dependency 'json', '~> 1.8'
23
+ end
@@ -0,0 +1,31 @@
1
+ module Infogram
2
+ class Client
3
+ API_URL = 'https://infogr.am/service/v1'
4
+
5
+ attr_accessor :config
6
+
7
+ def initialize(api_key, api_secret)
8
+ config(api_key: api_key, api_secret: api_secret)
9
+ end
10
+
11
+ def config(opts = {})
12
+ @config ||= {
13
+ api_key: opts[:api_key],
14
+ api_secret: opts[:api_secret],
15
+ api_url: API_URL
16
+ }
17
+ end
18
+
19
+ def themes
20
+ @themes ||= Infogram::Themes.new(config)
21
+ end
22
+
23
+ def infographics
24
+ @infographics ||= Infogram::Infographics.new(config)
25
+ end
26
+
27
+ def users
28
+ @users ||= Infogram::Users.new(config)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,39 @@
1
+ module Infogram
2
+ class Infographics < Resources
3
+ def initialize(config = {})
4
+ @config = config
5
+ end
6
+
7
+ def list(opts = {})
8
+ opts[:api_key] = @config[:api_key]
9
+ opts[:api_sig] = signature('GET', 'infographics', opts, @config)
10
+ HTTParty.get("#{@config[:api_url]}/infographics", query: opts)
11
+ end
12
+
13
+ def get(id, opts = {})
14
+ opts[:api_key] = @config[:api_key]
15
+ opts[:api_sig] = signature('GET', "infographics/#{id}", opts, @config)
16
+ HTTParty.get("#{@config[:api_url]}/infographics/#{id}", query: opts)
17
+ end
18
+
19
+ def create(opts = {})
20
+ opts[:api_key] = @config[:api_key]
21
+ opts[:api_sig] = signature('POST', 'infographics', opts, @config)
22
+ opts[:content] = opts[:content].to_json
23
+ HTTParty.post("#{@config[:api_url]}/infographics", body: opts)
24
+ end
25
+
26
+ def update(id, opts = {})
27
+ opts[:api_key] = @config[:api_key]
28
+ opts[:api_sig] = signature('PUT', "infographics/#{id}", opts, @config)
29
+ opts[:content] = opts[:content].to_json
30
+ HTTParty.put("#{@config[:api_url]}/infographics/#{id}", body: opts)
31
+ end
32
+
33
+ def destroy(id, opts = {})
34
+ opts[:api_key] = @config[:api_key]
35
+ opts[:api_sig] = signature('DELETE', "infographics/#{id}", opts, @config)
36
+ HTTParty.delete("#{@config[:api_url]}/infographics/#{id}", body: opts)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ module Infogram
2
+ class Resources
3
+ def decode_params(params)
4
+ params.keys.sort.map { |k| "#{k}=#{url_escaping(params[k].to_s)}" }.join('&')
5
+ end
6
+
7
+ def url_escaping(string)
8
+ CGI.escape(string).gsub('+', '%20')
9
+ end
10
+
11
+ def signature(method, path, params, config)
12
+ string_to_sign = [
13
+ method.upcase,
14
+ url_escaping("#{config[:api_url]}/#{path}"),
15
+ url_escaping(decode_params(params))
16
+ ].compact.join('&')
17
+ raw_hmac = OpenSSL::HMAC.digest('sha1', config[:api_secret], string_to_sign)
18
+ Base64.encode64(raw_hmac)[0..-2]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Infogram
2
+ class Themes < Resources
3
+ def initialize(config = {})
4
+ @config = config
5
+ end
6
+
7
+ def list(opts = {})
8
+ opts[:api_key] = @config[:api_key]
9
+ opts[:api_sig] = signature('GET', 'themes', opts, @config)
10
+ HTTParty.get("#{@config[:api_url]}/themes", query: opts)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ module Infogram
2
+ class Users < Resources
3
+ def initialize(config = {})
4
+ @config = config
5
+ end
6
+
7
+ def get(id, opts = {})
8
+ opts[:api_key] = @config[:api_key]
9
+ opts[:api_sig] = signature('GET', "users/#{id}", opts, @config)
10
+ HTTParty.get("#{@config[:api_url]}/users/#{id}", query: opts)
11
+ end
12
+
13
+ def get_infographics(id, opts = {})
14
+ opts[:api_key] = @config[:api_key]
15
+ opts[:api_sig] = signature('GET', "users/#{id}/infographics", opts, @config)
16
+ HTTParty.get("#{@config[:api_url]}/users/#{id}/infographics", query: opts)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Infogram
2
+ VERSION = '1.0.0'
3
+ end
data/lib/infogram.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'httparty'
2
+ require 'json'
3
+ require 'cgi'
4
+
5
+ require 'infogram/version'
6
+ require 'infogram/resources'
7
+ require 'infogram/client'
8
+ require 'infogram/themes'
9
+ require 'infogram/infographics'
10
+ require 'infogram/users'
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "d819d9b7-67fb-40ec-9400-d63cc209aea8",
3
+ "title": "sample infographic 2",
4
+ "theme_id": 32,
5
+ "published": true,
6
+ "thumbnail_url": "https://s3-eu-west-1.amazonaws.com/infogram-thumbs-200/d819d9b7-67fb-40ec-9400-d63cc209aea8.jpg",
7
+ "date_modified": "2014-12-19T09:32:52.000Z",
8
+ "url": "https://infogr.am/sample-infographic-28",
9
+ "embed_responsive": "<script id=\"infogram_0_sample-infographic-28\" src=\"//e.infogr.am/js/embed.js?zni\" type=\"text/javascript\"></script><div style=\"width:100%;border-top:1px solid #acacac;padding-top:3px;font-family:Arial;font-size:10px;text-align:center;\"><a target=\"_blank\" href=\"https://infogr.am/sample-infographic-28\" style=\"color:#acacac;text-decoration:none;\">sample infographic 2</a> |<a style=\"color:#acacac;text-decoration:none;\" href=\"https://infogr.am\" target=\"_blank\">Create infographics</a></div>"
10
+ }
@@ -0,0 +1,21 @@
1
+ [
2
+ {
3
+ "id": "309b6f66-83d2-437e-84d3-edb76035b771",
4
+ "title": "Sample infographic 1",
5
+ "theme_id": 29,
6
+ "published": false,
7
+ "thumbnail_url": "https://s3-eu-west-1.amazonaws.com/infogram-thumbs-200/309b6f66-83d2-437e-84d3-edb76035b771.jpg",
8
+ "date_modified": "2014-12-09T13:28:36.000Z",
9
+ "user_profile": "infogram_demo"
10
+ }, {
11
+ "id": "d819d9b7-67fb-40ec-9400-d63cc209aea8",
12
+ "title": "sample infographic 2",
13
+ "theme_id": 32,
14
+ "published": true,
15
+ "thumbnail_url": "https://s3-eu-west-1.amazonaws.com/infogram-thumbs-200/d819d9b7-67fb-40ec-9400-d63cc209aea8.jpg",
16
+ "date_modified": "2014-12-19T09:32:52.000Z",
17
+ "user_profile": "infogram_demo",
18
+ "url": "https://infogr.am/sample-infographic-28",
19
+ "embed_responsive": "<script id=\"infogram_0_sample-infographic-28\" src=\"//e.infogr.am/js/embed.js?xvj\" type=\"text/javascript\"></script><div style=\"width:100%;border-top:1px solid #acacac;padding-top:3px;font-family:Arial;font-size:10px;text-align:center;\"><a target=\"_blank\" href=\"https://infogr.am/sample-infographic-28\" style=\"color:#acacac;text-decoration:none;\">sample infographic 2</a> |<a style=\"color:#acacac;text-decoration:none;\" href=\"https://infogr.am\" target=\"_blank\">Create infographics</a></div>"
20
+ }
21
+ ]
@@ -0,0 +1,17 @@
1
+ [
2
+ {
3
+ "id":61,
4
+ "title":"twitter",
5
+ "thumbnail_url":"https://infogr.am/i/templates/61/twitter-thumbnail-small.png"
6
+ },
7
+ {
8
+ "id":44,
9
+ "title":"Megaphone",
10
+ "thumbnail_url":"https://infogr.am/i/templates/S/PRO-megaphone.png"
11
+ },
12
+ {
13
+ "id":34,
14
+ "title":"Asketic-new",
15
+ "thumbnail_url":"https://infogr.am/i/templates/S/asketic-black.png"
16
+ }
17
+ ]
data/spec/helper.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'infogram'
2
+ require 'rspec'
3
+ require 'webmock/rspec'
4
+
5
+ WebMock.disable_net_connect!
6
+
7
+ RSpec.configure do |config|
8
+ config.expect_with :rspec do |c|
9
+ c.syntax = :expect
10
+ end
11
+ end
12
+
13
+ def infogram_client(key, secret)
14
+ Infogram::Client.new(key, secret)
15
+ end
16
+
17
+ def fixture(file)
18
+ File.read('spec/fixtures/' + file)
19
+ end
20
+
21
+ def with_fixture(file)
22
+ {
23
+ body: fixture(file),
24
+ headers: { content_type: 'application/json; charset=utf-8' }
25
+ }
26
+ end
27
+
28
+ def stub_get(path)
29
+ stub_request(:get, /.*#{Infogram::Client::API_URL + '/' + path}*/)
30
+ end
31
+
32
+ def stub_post(path)
33
+ stub_request(:post, /.*#{Infogram::Client::API_URL + '/' + path}*/)
34
+ end
@@ -0,0 +1,58 @@
1
+ require 'helper'
2
+
3
+ describe 'Infogram' do
4
+ let(:api_key) { 'nMECGhmHe9' }
5
+ let(:api_secret) { 'da5xoLrCCx' }
6
+ let(:client) { infogram_client(api_key, api_secret) }
7
+ let(:ig_id) { 'd819d9b7-67fb-40ec-9400-d63cc209aea8' }
8
+ let(:params) {
9
+ {
10
+ content: [
11
+ {
12
+ type: 'h1',
13
+ text: 'Hello infogr.am'
14
+ }
15
+ ],
16
+ theme_id: 45,
17
+ publish: false,
18
+ title: 'Hello'
19
+ }
20
+ }
21
+
22
+ context 'Themes' do
23
+ it 'should return themes list' do
24
+ stub_get('themes').to_return(with_fixture('themes.json'))
25
+ themes = client.themes.list
26
+ expect(themes[0]['id']).to eq(61)
27
+ expect(themes[1]['title']).to eq('Megaphone')
28
+ end
29
+ end
30
+
31
+ context 'Infographics' do
32
+ it 'GET infographics' do
33
+ stub_get('infographics').to_return(with_fixture('infographics.json'))
34
+ infographics = client.infographics.list
35
+ expect(infographics[1]['id']).to eq(ig_id)
36
+ end
37
+
38
+ it 'GET infographics/:id' do
39
+ stub_get('infographics').to_return(with_fixture('infographic.json'))
40
+ infographic = client.infographics.get(ig_id)
41
+ expect(infographic['title']).to eq('sample infographic 2')
42
+ end
43
+
44
+ it 'POST infographics' do
45
+ stub_post('infographics').to_return(with_fixture('infographic.json'))
46
+ infographic = client.infographics.create(params)
47
+ expect(infographic['title']).to eq('sample infographic 2')
48
+ end
49
+ end
50
+
51
+ context 'Users' do
52
+ it 'GET Users infographics' do
53
+ stub_get('users').to_return(with_fixture('infographics.json'))
54
+ infographics = client.users.get_infographics('abc')
55
+ expect(infographics[1]['id']).to eq(ig_id)
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infogram
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Maksim Berjoza
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.13'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ description: Ruby library for Infogr.am
70
+ email:
71
+ - torbjon@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - Guardfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - infogram.gemspec
84
+ - lib/infogram.rb
85
+ - lib/infogram/client.rb
86
+ - lib/infogram/infographics.rb
87
+ - lib/infogram/resources.rb
88
+ - lib/infogram/themes.rb
89
+ - lib/infogram/users.rb
90
+ - lib/infogram/version.rb
91
+ - spec/fixtures/infographic.json
92
+ - spec/fixtures/infographics.json
93
+ - spec/fixtures/themes.json
94
+ - spec/helper.rb
95
+ - spec/infogram_spec.rb
96
+ homepage: https://github.com/infogram/infogram-ruby
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.5
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Infogr.am Ruby SDK
120
+ test_files:
121
+ - spec/fixtures/infographic.json
122
+ - spec/fixtures/infographics.json
123
+ - spec/fixtures/themes.json
124
+ - spec/helper.rb
125
+ - spec/infogram_spec.rb