Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

restructured code, so it can be packages as a gem

  • Loading branch information...
commit beecf94b02285da1cb4d1d46a4366124dafeab70 1 parent ebee975
Matin Tamizi matin authored
1  .gitignore
... ... @@ -0,0 +1 @@
  1 +pkg/
1  .rvmrc
... ... @@ -0,0 +1 @@
  1 +rvm use --create --install 1.9.2@poundpay >& /dev/null
4 Gemfile
... ... @@ -0,0 +1,4 @@
  1 +source "http://rubygems.org"
  2 +
  3 +# Specify your gem's dependencies in poundpay.gemspec
  4 +gemspec
2  Rakefile
... ... @@ -0,0 +1,2 @@
  1 +require 'bundler'
  2 +Bundler::GemHelper.install_tasks
77 lib/poundpay.rb
... ... @@ -1,72 +1,18 @@
1   -require 'cgi'
2   -
3   -require 'active_resource'
4   -require 'active_resource/formats'
5   -
6   -
7   -module ActiveResource
8   - module Formats
9   - module UrlencodedJsonFormat
10   - extend self
11   -
12   - def extension
13   - "json"
14   - end
15   -
16   - def mime_type
17   - "application/x-www-form-urlencoded"
18   - end
19   -
20   - def decode(json)
21   - ActiveSupport::JSON.decode(json)
22   - end
23   - end
24   - end
25   -end
26   -
  1 +require 'poundpay/resource'
27 2
28 3 module Poundpay
29   - class PoundpayResource < ActiveResource::Base
30   - self.site = "http://localhost:8000/silver/"
31   - self.user = "DV8539761e250011e0a81d1231400042c7"
32   - self.password = "5d291d63059f5c2fe8d144820a847982a9fba7004a1009a35ed7a5fdf1f67960"
33   - self.format = ActiveResource::Formats::UrlencodedJsonFormat
34   -
35   - class << self
36   - attr_accessor_with_default(:primary_key, 'sid')
37   -
38   - def element_path(id, prefix_options = {}, query_options = nil)
39   - prefix_options, query_options = split_options(prefix_options) if query_options.nil?
40   - "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}#{query_string(query_options)}"
41   - end
42   -
43   - def new_element_path(prefix_options = {})
44   - "#{prefix(prefix_options)}#{collection_name}/new"
45   - end
46   -
47   - def collection_path(prefix_options = {}, query_options = nil)
48   - prefix_options, query_options = split_options(prefix_options) if query_options.nil?
49   - "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
50   - end
51   -
52   - def instantiate_collection(collection, prefix_options = {})
53   - # TODO: Consume pages
54   - collection = collection[collection_name]
55   - super(collection, prefix_options)
56   - end
57   - end
58   -
59   - def encode
60   - @attributes.to_a.collect { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join("&")
61   - end
62   -
63   - def collection_name
64   - self.class.collection_name
  4 + API_URL = "https://api.poundpay.com"
  5 + VERSION = "silver"
  6 +
  7 + class << self
  8 + def configure(sid, token, api_url=API_URL, version=VERSION)
  9 + Resource.site = "#{api_url}/#{version}/"
  10 + Resource.user = sid
  11 + Resource.password = token
65 12 end
66 13 end
67 14
68   -
69   - class Developer < PoundpayResource
  15 + class Developer < Resource
70 16 class << self
71 17 def me
72 18 find(self.user)
@@ -74,8 +20,7 @@ def me
74 20 end
75 21 end
76 22
77   -
78   - class Payment < PoundpayResource
  23 + class Payment < Resource
79 24 def release
80 25 self.status = 'RELEASED'
81 26 self.save
14 lib/poundpay/formats.rb
... ... @@ -0,0 +1,14 @@
  1 +require 'active_resource/formats/json_format'
  2 +
  3 +module Poundpay
  4 + module Formats
  5 + module UrlencodedJsonFormat
  6 + extend ActiveResource::Formats::JsonFormat
  7 + extend self
  8 +
  9 + def mime_type
  10 + "application/x-www-form-urlencoded"
  11 + end
  12 + end
  13 + end
  14 +end
52 lib/poundpay/resource.rb
... ... @@ -0,0 +1,52 @@
  1 +require 'cgi'
  2 +require 'active_resource'
  3 +require 'poundpay/formats'
  4 +
  5 +module Poundpay
  6 + class Resource < ActiveResource::Base
  7 + self.format = Formats::UrlencodedJsonFormat
  8 +
  9 + class << self
  10 + attr_accessor_with_default(:primary_key, 'sid')
  11 +
  12 + # Modified default to not use an extension
  13 + def element_path(id, prefix_options = {}, query_options = nil)
  14 + prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  15 + "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}#{query_string(query_options)}"
  16 + end
  17 +
  18 + # Modified default to not use an extension
  19 + def new_element_path(prefix_options = {})
  20 + "#{prefix(prefix_options)}#{collection_name}/new"
  21 + end
  22 +
  23 + # Modified default to not use an extension
  24 + def collection_path(prefix_options = {}, query_options = nil)
  25 + prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  26 + "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
  27 + end
  28 +
  29 + # Handle paginated collections
  30 + def instantiate_collection(collection, prefix_options = {})
  31 + # TODO: Consume pages
  32 + collection = collection[collection_name]
  33 + super(collection, prefix_options)
  34 + end
  35 + end
  36 +
  37 + # Poundpay accepts urlencoded form parameters
  38 + # Ideally we should override this functionality in the format, but it's not very straightforward to do so
  39 + def encode
  40 + urlencode(@attributes)
  41 + end
  42 +
  43 + def collection_name
  44 + self.class.collection_name
  45 + end
  46 +
  47 + protected
  48 + def urlencode(params)
  49 + params.to_a.collect! { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join("&")
  50 + end
  51 + end
  52 +end
3  lib/poundpay/version.rb
... ... @@ -0,0 +1,3 @@
  1 +module Poundpay
  2 + VERSION = "0.0.1"
  3 +end
23 poundpay.gemspec
... ... @@ -0,0 +1,23 @@
  1 +# -*- encoding: utf-8 -*-
  2 +$:.push File.expand_path("../lib", __FILE__)
  3 +require "poundpay/version"
  4 +
  5 +Gem::Specification.new do |s|
  6 + s.name = "poundpay"
  7 + s.version = Poundpay::VERSION
  8 + s.platform = Gem::Platform::RUBY
  9 + s.authors = ["Matin Tamizi"]
  10 + s.email = "devsupport@poundpay.com"
  11 + s.homepage = "http://github.com/poundpay/poundpay-ruby"
  12 + s.summary = %q{Poundpay Ruby library}
  13 + s.description = %q{Payments platform for marketplaces}
  14 +
  15 + s.rubyforge_project = "poundpay"
  16 +
  17 + s.add_dependency("activeresource", ">= 3.0")
  18 +
  19 + s.files = `git ls-files`.split("\n")
  20 + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
  21 + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
  22 + s.require_paths = ["lib"]
  23 +end

0 comments on commit beecf94

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