infogram-ruby 0.0.1 → 0.0.2
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 +4 -4
- data/.gitignore +7 -14
- data/infogram-ruby.gemspec +1 -1
- data/spec/helper.rb +1 -1
- metadata +1 -4
- data/lib/infogram.rb +0 -59
- data/spec/infogram_spec.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c506de4569cbef7cc17a74fe6e23eaf9c027ae4a
|
4
|
+
data.tar.gz: e0206530c3695c98f4460391bb0ff471218da4c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9194557c5bf6e8b65bb73855e8e76cd03ec05e0119dda542d15979894e2146e06d3d13f45906adcca4c26390c66cef5547ce4918937cd9615bd16b871c906bd
|
7
|
+
data.tar.gz: 60921e4df0f4645806a893a6549ca161cbf044c14bb86336b1c548afca5f31e6f4481eddd0cecf3c695752d59dd1a7b06eb9b8c2b89110c21997ec56dd1547c5
|
data/.gitignore
CHANGED
data/infogram-ruby.gemspec
CHANGED
data/spec/helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infogram-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maksim Berjoza
|
@@ -81,12 +81,10 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
83
|
- infogram-ruby.gemspec
|
84
|
-
- lib/infogram.rb
|
85
84
|
- spec/fixtures/infographic.json
|
86
85
|
- spec/fixtures/infographics.json
|
87
86
|
- spec/fixtures/themes.json
|
88
87
|
- spec/helper.rb
|
89
|
-
- spec/infogram_spec.rb
|
90
88
|
homepage: ''
|
91
89
|
licenses:
|
92
90
|
- MIT
|
@@ -116,4 +114,3 @@ test_files:
|
|
116
114
|
- spec/fixtures/infographics.json
|
117
115
|
- spec/fixtures/themes.json
|
118
116
|
- spec/helper.rb
|
119
|
-
- spec/infogram_spec.rb
|
data/lib/infogram.rb
DELETED
@@ -1,59 +0,0 @@
|
|
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
|
data/spec/infogram_spec.rb
DELETED
@@ -1,63 +0,0 @@
|
|
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
|