infogram-ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Guardfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/infogram-ruby.gemspec +24 -0
- data/lib/infogram.rb +59 -0
- data/spec/fixtures/infographic.json +10 -0
- data/spec/fixtures/infographics.json +21 -0
- data/spec/fixtures/themes.json +17 -0
- data/spec/helper.rb +31 -0
- data/spec/infogram_spec.rb +63 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 730e604ebd01a18f4a95bed79f71d87f899148e7
|
4
|
+
data.tar.gz: f180b6d0d90ef30188ecf6f976e72865f9495266
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9246c407594fe0eca9ba96d5f475729254d382d38e94f741eeccbcfbe0c54940fb48279e0cdf2e8169435ee55a066db32b8ebaa1d99378da15943318ebd8a608
|
7
|
+
data.tar.gz: ece68ceaa4130fa96d7b51bf469ca479cd51a6175c1da8ff35f2763f30ea548ff4127b40c789a3517c156f212598740757ef6494722b60ca615fbe3f8c8c5301
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Guardfile
ADDED
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,55 @@
|
|
1
|
+
# Infogram::Ruby
|
2
|
+
|
3
|
+
Ruby library for Infogr.am
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'infogram-ruby'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install infogram-ruby
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
```ruby
|
23
|
+
infogram = Infogram.new('API_KEY', 'API_SECRET')
|
24
|
+
client.get_themes
|
25
|
+
```
|
26
|
+
## Example response
|
27
|
+
```json
|
28
|
+
[
|
29
|
+
{
|
30
|
+
"id": 61,
|
31
|
+
"title": "twitter",
|
32
|
+
"thumb": "https://infogr.am/i/templates/61/twitter-thumbnail-small.png"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"id": 44,
|
36
|
+
"title": "Megaphone",
|
37
|
+
"thumb": "https://infogr.am/i/templates/S/PRO-megaphone.png"
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"id": 34,
|
41
|
+
"title": "Asketic-new",
|
42
|
+
"thumb": "https://infogr.am/i/templates/S/asketic-black.png"
|
43
|
+
}
|
44
|
+
]
|
45
|
+
```
|
46
|
+
|
47
|
+
## API Methods
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/[my-github-username]/infogram-ruby/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'infogram-ruby'
|
7
|
+
s.version = '0.0.1'
|
8
|
+
s.authors = ['Maksim Berjoza']
|
9
|
+
s.email = ['torbjon@gmail.com']
|
10
|
+
s.summary = %q{Infogr.am Ruby SDK}
|
11
|
+
s.description = %q{Ruby library for Infogr.am}
|
12
|
+
s.homepage = ''
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files -z`.split("\x0")
|
16
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.add_development_dependency 'bundler', '~> 1.7'
|
21
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
s.add_dependency 'httparty', '~> 0.13'
|
23
|
+
s.add_dependency 'json', '~> 1.8'
|
24
|
+
end
|
data/lib/infogram.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
class Infogram
|
6
|
+
API_URL = 'https://infogr.am/service/v1'
|
7
|
+
|
8
|
+
attr_accessor :api_key, :api_secret, :api_url
|
9
|
+
|
10
|
+
def initialize(api_key, api_secret)
|
11
|
+
@api_key = api_key
|
12
|
+
@api_secret = api_secret
|
13
|
+
@api_url = API_URL
|
14
|
+
end
|
15
|
+
|
16
|
+
def decode_params(params)
|
17
|
+
params.keys.sort.map{ |k|
|
18
|
+
value = (k.to_s == 'content') ? url_escaping(params[k].to_json) : params[k]
|
19
|
+
"#{k}=#{value}"
|
20
|
+
}.join('&')
|
21
|
+
end
|
22
|
+
|
23
|
+
def signature(method, path, params)
|
24
|
+
string_to_sign = [method.upcase, url_escaping("#{api_url}/#{path}"), url_escaping(decode_params(params))].compact.join('&')
|
25
|
+
raw_hmac = OpenSSL::HMAC.digest('sha1', api_secret, string_to_sign)
|
26
|
+
Base64.encode64(raw_hmac)[0..-2]
|
27
|
+
end
|
28
|
+
|
29
|
+
def url_escaping(string)
|
30
|
+
CGI.escape(string).gsub('+', '%20')
|
31
|
+
end
|
32
|
+
|
33
|
+
# themes
|
34
|
+
def get_themes(opts={})
|
35
|
+
opts[:api_key] = @api_key
|
36
|
+
opts[:api_sig] = signature('GET', 'themes', opts)
|
37
|
+
HTTParty.get("#{@api_url}/themes", query: opts)
|
38
|
+
end
|
39
|
+
|
40
|
+
# infographics
|
41
|
+
def get_infographics(opts={})
|
42
|
+
opts[:api_key] = @api_key
|
43
|
+
opts[:api_sig] = signature('GET', "infographics", opts)
|
44
|
+
HTTParty.get("#{@api_url}/infographics", query: opts)
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_infographic(id, opts={})
|
48
|
+
opts[:api_key] = @api_key
|
49
|
+
opts[:api_sig] = signature('GET', "infographics/#{id}", opts)
|
50
|
+
HTTParty.get("#{@api_url}/infographics/#{id}", query: opts)
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_infographic(opts={})
|
54
|
+
opts[:api_key] = @api_key
|
55
|
+
opts[:api_sig] = signature('POST', 'infographics', opts)
|
56
|
+
opts[:content] = opts[:content].to_json
|
57
|
+
HTTParty.post("#{@api_url}/infographics", body: opts)
|
58
|
+
end
|
59
|
+
end
|
@@ -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,31 @@
|
|
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.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
|
+
{ body: fixture(file), headers: { content_type: 'application/json; charset=utf-8' } }
|
23
|
+
end
|
24
|
+
|
25
|
+
def stub_get(path)
|
26
|
+
stub_request(:get, /.*#{Infogram::API_URL + '/' + path}*/)
|
27
|
+
end
|
28
|
+
|
29
|
+
def stub_post(path)
|
30
|
+
stub_request(:post, /.*#{Infogram::API_URL + '/' + path}*/)
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
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 (:params) { {
|
8
|
+
content: [
|
9
|
+
{
|
10
|
+
type: 'h1',
|
11
|
+
text: 'Hello infogr.am'
|
12
|
+
}
|
13
|
+
],
|
14
|
+
theme_id: 45,
|
15
|
+
publish: false,
|
16
|
+
title: 'Hello'
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
context 'Signature' do
|
21
|
+
let (:encoded_params) { 'api_key=nMECGhmHe9&content=%5B%7B%22type%22%3A%22h1%22%2C%22text%22%3A%22Hello%20infogr.am%22%7D%5D&publish=false&theme_id=45&title=Hello' }
|
22
|
+
|
23
|
+
it 'should encode params' do
|
24
|
+
params[:api_key] = api_key
|
25
|
+
expect(client.decode_params(params)).to eq(encoded_params)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should generate signature' do
|
29
|
+
params[:api_key] = api_key
|
30
|
+
signature = client.signature('post', 'infographics', params)
|
31
|
+
expect(signature).to eq('bqwCqAk1TWDYNy3eqV0BiNuIERQ=')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'Themes' do
|
36
|
+
it 'should return themes list' do
|
37
|
+
stub_get('themes').to_return(with_fixture('themes.json'))
|
38
|
+
themes = client.get_themes()
|
39
|
+
expect(themes[0]['id']).to eq(61)
|
40
|
+
expect(themes[1]['title']).to eq('Megaphone')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'Infographic' do
|
45
|
+
it 'GET infographics' do
|
46
|
+
stub_get('infographics').to_return(with_fixture('infographics.json'))
|
47
|
+
ig = client.get_infographics
|
48
|
+
expect(ig[1]['id']).to eq('d819d9b7-67fb-40ec-9400-d63cc209aea8')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'GET infographics/:id' do
|
52
|
+
stub_get('infographics').to_return(with_fixture('infographic.json'))
|
53
|
+
ig = client.get_infographic('d819d9b7-67fb-40ec-9400-d63cc209aea8')
|
54
|
+
expect(ig['title']).to eq('sample infographic 2')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'POST infographics' do
|
58
|
+
stub_post('infographics').to_return(with_fixture('infographic.json'))
|
59
|
+
ig = client.create_infographic(params)
|
60
|
+
expect(ig['title']).to eq('sample infographic 2')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: infogram-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maksim Berjoza
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-28 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-ruby.gemspec
|
84
|
+
- lib/infogram.rb
|
85
|
+
- spec/fixtures/infographic.json
|
86
|
+
- spec/fixtures/infographics.json
|
87
|
+
- spec/fixtures/themes.json
|
88
|
+
- spec/helper.rb
|
89
|
+
- spec/infogram_spec.rb
|
90
|
+
homepage: ''
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.3
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Infogr.am Ruby SDK
|
114
|
+
test_files:
|
115
|
+
- spec/fixtures/infographic.json
|
116
|
+
- spec/fixtures/infographics.json
|
117
|
+
- spec/fixtures/themes.json
|
118
|
+
- spec/helper.rb
|
119
|
+
- spec/infogram_spec.rb
|