Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib rewrite, new methods, readme update, version bump
- Loading branch information
Showing
14 changed files
with
226 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
guard 'rspec', cmd: 'bundle exec rspec' do | ||
watch(%r{^spec/.+_spec\.rb$}) | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'httparty' | ||
require 'json' | ||
require 'cgi' | ||
|
||
require 'infogram/version' | ||
require 'infogram/resources' | ||
require 'infogram/client' | ||
require 'infogram/themes' | ||
require 'infogram/infographics' | ||
require 'infogram/users' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Infogram | ||
class Client | ||
API_URL = 'https://infogr.am/service/v1' | ||
|
||
attr_accessor :config | ||
|
||
def initialize(api_key, api_secret) | ||
config(api_key: api_key, api_secret: api_secret) | ||
end | ||
|
||
def config(opts = {}) | ||
@config ||= { | ||
api_key: opts[:api_key], | ||
api_secret: opts[:api_secret], | ||
api_url: API_URL | ||
} | ||
end | ||
|
||
def themes | ||
@themes ||= Infogram::Themes.new(config) | ||
end | ||
|
||
def infographics | ||
@infographics ||= Infogram::Infographics.new(config) | ||
end | ||
|
||
def users | ||
@users ||= Infogram::Users.new(config) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Infogram | ||
class Infographics < Resources | ||
def initialize(config = {}) | ||
@config = config | ||
end | ||
|
||
def list(opts = {}) | ||
opts[:api_key] = @config[:api_key] | ||
opts[:api_sig] = signature('GET', 'infographics', opts, @config) | ||
HTTParty.get("#{@config[:api_url]}/infographics", query: opts) | ||
end | ||
|
||
def get(id, opts = {}) | ||
opts[:api_key] = @config[:api_key] | ||
opts[:api_sig] = signature('GET', "infographics/#{id}", opts, @config) | ||
HTTParty.get("#{@config[:api_url]}/infographics/#{id}", query: opts) | ||
end | ||
|
||
def create(opts = {}) | ||
opts[:api_key] = @config[:api_key] | ||
opts[:api_sig] = signature('POST', 'infographics', opts, @config) | ||
opts[:content] = opts[:content].to_json | ||
HTTParty.post("#{@config[:api_url]}/infographics", body: opts) | ||
end | ||
|
||
def update(id, opts = {}) | ||
opts[:api_key] = @config[:api_key] | ||
opts[:api_sig] = signature('PUT', "infographics/#{id}", opts, @config) | ||
opts[:content] = opts[:content].to_json | ||
HTTParty.put("#{@config[:api_url]}/infographics/#{id}", body: opts) | ||
end | ||
|
||
def destroy(id, opts = {}) | ||
opts[:api_key] = @config[:api_key] | ||
opts[:api_sig] = signature('DELETE', "infographics/#{id}", opts, @config) | ||
HTTParty.delete("#{@config[:api_url]}/infographics/#{id}", body: opts) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Infogram | ||
class Resources | ||
def decode_params(params) | ||
params.keys.sort.map { |k| "#{k}=#{url_escaping(params[k].to_s)}" }.join('&') | ||
end | ||
|
||
def url_escaping(string) | ||
CGI.escape(string).gsub('+', '%20') | ||
end | ||
|
||
def signature(method, path, params, config) | ||
string_to_sign = [ | ||
method.upcase, | ||
url_escaping("#{config[:api_url]}/#{path}"), | ||
url_escaping(decode_params(params)) | ||
].compact.join('&') | ||
raw_hmac = OpenSSL::HMAC.digest('sha1', config[:api_secret], string_to_sign) | ||
Base64.encode64(raw_hmac)[0..-2] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Infogram | ||
class Themes < Resources | ||
def initialize(config = {}) | ||
@config = config | ||
end | ||
|
||
def list(opts = {}) | ||
opts[:api_key] = @config[:api_key] | ||
opts[:api_sig] = signature('GET', 'themes', opts, @config) | ||
HTTParty.get("#{@config[:api_url]}/themes", query: opts) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Infogram | ||
class Users < Resources | ||
def initialize(config = {}) | ||
@config = config | ||
end | ||
|
||
def get(id, opts = {}) | ||
opts[:api_key] = @config[:api_key] | ||
opts[:api_sig] = signature('GET', "users/#{id}", opts, @config) | ||
HTTParty.get("#{@config[:api_url]}/users/#{id}", query: opts) | ||
end | ||
|
||
def get_infographics(id, opts = {}) | ||
opts[:api_key] = @config[:api_key] | ||
opts[:api_sig] = signature('GET', "users/#{id}/infographics", opts, @config) | ||
HTTParty.get("#{@config[:api_url]}/users/#{id}/infographics", query: opts) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Infogram | ||
VERSION = '1.0.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.