Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

restructured code, so it can be packages as a gem

  • Loading branch information...
commit beecf94b02285da1cb4d1d46a4366124dafeab70 1 parent ebee975
@matin matin authored
View
1  .gitignore
@@ -0,0 +1 @@
+pkg/
View
1  .rvmrc
@@ -0,0 +1 @@
+rvm use --create --install 1.9.2@poundpay >& /dev/null
View
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in poundpay.gemspec
+gemspec
View
2  Rakefile
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
View
77 lib/poundpay.rb
@@ -1,72 +1,18 @@
-require 'cgi'
-
-require 'active_resource'
-require 'active_resource/formats'
-
-
-module ActiveResource
- module Formats
- module UrlencodedJsonFormat
- extend self
-
- def extension
- "json"
- end
-
- def mime_type
- "application/x-www-form-urlencoded"
- end
-
- def decode(json)
- ActiveSupport::JSON.decode(json)
- end
- end
- end
-end
-
+require 'poundpay/resource'
module Poundpay
- class PoundpayResource < ActiveResource::Base
- self.site = "http://localhost:8000/silver/"
- self.user = "DV8539761e250011e0a81d1231400042c7"
- self.password = "5d291d63059f5c2fe8d144820a847982a9fba7004a1009a35ed7a5fdf1f67960"
- self.format = ActiveResource::Formats::UrlencodedJsonFormat
-
- class << self
- attr_accessor_with_default(:primary_key, 'sid')
-
- def element_path(id, prefix_options = {}, query_options = nil)
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
- "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}#{query_string(query_options)}"
- end
-
- def new_element_path(prefix_options = {})
- "#{prefix(prefix_options)}#{collection_name}/new"
- end
-
- def collection_path(prefix_options = {}, query_options = nil)
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
- "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
- end
-
- def instantiate_collection(collection, prefix_options = {})
- # TODO: Consume pages
- collection = collection[collection_name]
- super(collection, prefix_options)
- end
- end
-
- def encode
- @attributes.to_a.collect { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join("&")
- end
-
- def collection_name
- self.class.collection_name
+ API_URL = "https://api.poundpay.com"
+ VERSION = "silver"
+
+ class << self
+ def configure(sid, token, api_url=API_URL, version=VERSION)
+ Resource.site = "#{api_url}/#{version}/"
+ Resource.user = sid
+ Resource.password = token
end
end
-
- class Developer < PoundpayResource
+ class Developer < Resource
class << self
def me
find(self.user)
@@ -74,8 +20,7 @@ def me
end
end
-
- class Payment < PoundpayResource
+ class Payment < Resource
def release
self.status = 'RELEASED'
self.save
View
14 lib/poundpay/formats.rb
@@ -0,0 +1,14 @@
+require 'active_resource/formats/json_format'
+
+module Poundpay
+ module Formats
+ module UrlencodedJsonFormat
+ extend ActiveResource::Formats::JsonFormat
+ extend self
+
+ def mime_type
+ "application/x-www-form-urlencoded"
+ end
+ end
+ end
+end
View
52 lib/poundpay/resource.rb
@@ -0,0 +1,52 @@
+require 'cgi'
+require 'active_resource'
+require 'poundpay/formats'
+
+module Poundpay
+ class Resource < ActiveResource::Base
+ self.format = Formats::UrlencodedJsonFormat
+
+ class << self
+ attr_accessor_with_default(:primary_key, 'sid')
+
+ # Modified default to not use an extension
+ def element_path(id, prefix_options = {}, query_options = nil)
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
+ "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}#{query_string(query_options)}"
+ end
+
+ # Modified default to not use an extension
+ def new_element_path(prefix_options = {})
+ "#{prefix(prefix_options)}#{collection_name}/new"
+ end
+
+ # Modified default to not use an extension
+ def collection_path(prefix_options = {}, query_options = nil)
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
+ "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
+ end
+
+ # Handle paginated collections
+ def instantiate_collection(collection, prefix_options = {})
+ # TODO: Consume pages
+ collection = collection[collection_name]
+ super(collection, prefix_options)
+ end
+ end
+
+ # Poundpay accepts urlencoded form parameters
+ # Ideally we should override this functionality in the format, but it's not very straightforward to do so
+ def encode
+ urlencode(@attributes)
+ end
+
+ def collection_name
+ self.class.collection_name
+ end
+
+ protected
+ def urlencode(params)
+ params.to_a.collect! { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join("&")
+ end
+ end
+end
View
3  lib/poundpay/version.rb
@@ -0,0 +1,3 @@
+module Poundpay
+ VERSION = "0.0.1"
+end
View
23 poundpay.gemspec
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "poundpay/version"
+
+Gem::Specification.new do |s|
+ s.name = "poundpay"
+ s.version = Poundpay::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Matin Tamizi"]
+ s.email = "devsupport@poundpay.com"
+ s.homepage = "http://github.com/poundpay/poundpay-ruby"
+ s.summary = %q{Poundpay Ruby library}
+ s.description = %q{Payments platform for marketplaces}
+
+ s.rubyforge_project = "poundpay"
+
+ s.add_dependency("activeresource", ">= 3.0")
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end

0 comments on commit beecf94

Please sign in to comment.
Something went wrong with that request. Please try again.