Created
January 19, 2011 16:56
-
-
Save pupca/786443 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require "rubygems" | |
require 'httparty' | |
require 'json' | |
class NilClass | |
def method_missing(method, *args) | |
p method | |
method = method.to_s.gsub("_",".") | |
method = method.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } #Thanks for the gsub, Rails | |
method = method[0].chr.downcase + method[1..-1].gsub(/aim$/i, 'AIM') | |
args = {} unless args.length > 0 | |
args = args[0] if (args.class.to_s == "Array") | |
end | |
end | |
class String | |
def method_missing(method, *args) | |
p method | |
method = method.to_s.gsub("_",".") | |
method = method.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } #Thanks for the gsub, Rails | |
method = method[0].chr.downcase + method[1..-1].gsub(/aim$/i, 'AIM') | |
args = {} unless args.length > 0 | |
args = args[0] if (args.class.to_s == "Array") | |
end | |
end | |
module Paymo | |
class API | |
include HTTParty | |
default_timeout 30 | |
attr_accessor :apikey, :timeout | |
def initialize(apikey = nil, extra_params = {}) | |
@apikey = apikey | |
@default_params = {:apikey => apikey}.merge(extra_params) | |
end | |
def apikey=(value) | |
@apikey = value | |
@default_params = @default_params.merge({:apikey => @apikey}) | |
end | |
def base_api_url | |
"http://api.paymo.biz/service/" | |
end | |
def call(method, params = {}) | |
url = base_api_url + method | |
params = params.merge(@default_params) | |
p url | |
p params | |
response = API.post(url, :body => params.to_json, :timeout => @timeout) | |
begin | |
response = JSON.parse(response.body) | |
rescue | |
response = response.body | |
end | |
response | |
end | |
def method_missing(method, *args) | |
p method | |
method = method.to_s.gsub("_",".") | |
method = method.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } #Thanks for the gsub, Rails | |
method = method[0].chr.downcase + method[1..-1].gsub(/aim$/i, 'AIM') | |
args = {} unless args.length > 0 | |
args = args[0] if (args.class.to_s == "Array") | |
call(method, args) | |
end | |
end | |
end | |
paymo = Paymo::API.new("XXXX") | |
paymo.paymo.users.findByEmail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment