paymill 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - 2.0.0
data/README.md CHANGED
@@ -73,4 +73,4 @@ Note on Patches/Pull Requests
73
73
  Copyright
74
74
  ======
75
75
 
76
- Copyright (c) 2012 dkd Internet Service GmbH, Stefan Sprenger. See LICENSE for details.
76
+ Copyright (c) 2012-2013 dkd Internet Service GmbH, Stefan Sprenger. See LICENSE for details.
@@ -4,20 +4,20 @@ require "json"
4
4
  require "paymill/version"
5
5
 
6
6
  module Paymill
7
- API_BASE = "api.paymill.de"
7
+ API_BASE = "api.paymill.com"
8
8
  API_VERSION = "v2"
9
9
 
10
10
  @@api_key = nil
11
11
 
12
- autoload :Base, "paymill/base"
13
- autoload :Client, "paymill/client"
14
- autoload :Offer, "paymill/offer"
15
- autoload :Payment, "paymill/payment"
12
+ autoload :Base, "paymill/base"
13
+ autoload :Client, "paymill/client"
14
+ autoload :Offer, "paymill/offer"
15
+ autoload :Payment, "paymill/payment"
16
16
  autoload :Preauthorization, "paymill/preauthorization"
17
17
  autoload :Refund, "paymill/refund"
18
- autoload :Subscription, "paymill/subscription"
19
- autoload :Transaction, "paymill/transaction"
20
- autoload :Webhook, "paymill/webhook"
18
+ autoload :Subscription, "paymill/subscription"
19
+ autoload :Transaction, "paymill/transaction"
20
+ autoload :Webhook, "paymill/webhook"
21
21
 
22
22
  module Operations
23
23
  autoload :All, "paymill/operations/all"
@@ -34,14 +34,26 @@ module Paymill
34
34
  class APIError < PaymillError; end
35
35
 
36
36
  class << self
37
+ # Returns the set api key
38
+ #
39
+ # @return [String] The api key
37
40
  def api_key
38
41
  @@api_key
39
42
  end
40
43
 
44
+ # Sets the api key
45
+ #
46
+ # @param [String] api_key The api key
41
47
  def api_key=(api_key)
42
48
  @@api_key = api_key
43
49
  end
44
50
 
51
+ # Makes a request against the Paymill API
52
+ #
53
+ # @param [Symbol] http_method The http method to use, must be one of :get, :post, :put and :delete
54
+ # @param [String] api_url The API url to use
55
+ # @param [Hash] data The data to send, e.g. used when creating new objects.
56
+ # @return [Array] The parsed JSON response.
45
57
  def request(http_method, api_url, data)
46
58
  raise AuthenticationError if api_key.nil?
47
59
 
@@ -79,6 +91,11 @@ module Paymill
79
91
  data
80
92
  end
81
93
 
94
+ # Builds and encodes a URI using given path and params.
95
+ #
96
+ # @param [String] path The path to use
97
+ # @param [Array] params The params to use
98
+ # @return [String] The built URI.
82
99
  def path_with_params(path, params)
83
100
  unless params.empty?
84
101
  encoded_params = URI.encode_www_form(params)
@@ -6,17 +6,24 @@ module Paymill
6
6
 
7
7
  attr_accessor :created_at, :updated_at
8
8
 
9
+ # Initializes the object using the given attributes
10
+ #
11
+ # @param [Hash] attributes The attributes to use for initialization
9
12
  def initialize(attributes = {})
10
13
  set_attributes(attributes)
11
14
  parse_timestamps
12
15
  end
13
16
 
17
+ # Sets the attributes
18
+ #
19
+ # @param [Hash] attributes The attributes to initialize
14
20
  def set_attributes(attributes)
15
21
  attributes.each_pair do |key, value|
16
22
  instance_variable_set("@#{key}", value)
17
23
  end
18
24
  end
19
25
 
26
+ # Parses UNIX timestamps and creates Time objects.
20
27
  def parse_timestamps
21
28
  @created_at = Time.at(created_at) if created_at
22
29
  @updated_at = Time.at(updated_at) if updated_at
@@ -2,6 +2,10 @@ module Paymill
2
2
  module Operations
3
3
  module All
4
4
  module ClassMethods
5
+ # Retrieves all available objects from the Paymill API
6
+ #
7
+ # @param [Hash] options Options to pass to the API
8
+ # @return [Array] The available objects
5
9
  def all(options = {})
6
10
  response = Paymill.request(:get, "#{self.name.split("::").last.downcase}s/", options)
7
11
  results = []
@@ -2,6 +2,9 @@ module Paymill
2
2
  module Operations
3
3
  module Create
4
4
  module ClassMethods
5
+ # Creates a new object
6
+ #
7
+ # @param [Hash] attributes The attributes of the created object
5
8
  def create(attributes)
6
9
  response = Paymill.request(:post, "#{self.name.split("::").last.downcase}s", attributes)
7
10
  self.new(response["data"])
@@ -13,4 +16,4 @@ module Paymill
13
16
  end
14
17
  end
15
18
  end
16
- end
19
+ end
@@ -2,6 +2,9 @@ module Paymill
2
2
  module Operations
3
3
  module Delete
4
4
  module ClassMethods
5
+ # Deletes the given object
6
+ #
7
+ # @param [Integer] id The id of the object that gets deleted
5
8
  def delete(id)
6
9
  response = Paymill.request(:delete, "#{self.name.split("::").last.downcase}s/#{id}", {})
7
10
  true
@@ -13,4 +16,4 @@ module Paymill
13
16
  end
14
17
  end
15
18
  end
16
- end
19
+ end
@@ -2,6 +2,10 @@ module Paymill
2
2
  module Operations
3
3
  module Find
4
4
  module ClassMethods
5
+ # Finds a given object
6
+ #
7
+ # @param [Integer] id The id of the object that should be found
8
+ # @return [Paymill::Base] The found object
5
9
  def find(id)
6
10
  response = Paymill.request(:get, "#{self.name.split("::").last.downcase}s/#{id}", {})
7
11
  self.new(response["data"])
@@ -13,4 +17,4 @@ module Paymill
13
17
  end
14
18
  end
15
19
  end
16
- end
20
+ end
@@ -1,6 +1,9 @@
1
1
  module Paymill
2
2
  module Operations
3
3
  module Update
4
+ # Updates a object
5
+ #
6
+ # @param [Hash] attributes The attributes that should be updated
4
7
  def update_attributes(attributes)
5
8
  response = Paymill.request(:put, "#{self.class.name.split("::").last.downcase}s/#{id}", attributes)
6
9
  set_attributes(response["data"])
@@ -3,8 +3,9 @@ module Paymill
3
3
  include Paymill::Operations::Delete
4
4
  include Paymill::Operations::Update
5
5
 
6
- attr_accessor :id, :plan, :livemode, :cancel_at_period_end, :canceled_at, :client, :trial_start, :trial_end
6
+ attr_accessor :id, :offer, :livemode, :cancel_at_period_end, :canceled_at, :client, :trial_start, :trial_end
7
7
 
8
+ # Parses UNIX timestamps and creates Time objects
8
9
  def parse_timestamps
9
10
  super
10
11
  @canceled_at = Time.at(canceled_at) if canceled_at
@@ -1,3 +1,3 @@
1
1
  module Paymill
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe Paymill::Subscription do
4
4
  let(:valid_attributes) do
5
5
  {
6
- plan: {
6
+ offer: {
7
7
  name: "Nerd special",
8
8
  amount: 123,
9
9
  interval: "week"
@@ -24,9 +24,9 @@ describe Paymill::Subscription do
24
24
 
25
25
  describe "#initialize" do
26
26
  it "initializes all attributes correctly" do
27
- subscription.plan[:name].should eql("Nerd special")
28
- subscription.plan[:amount].should eql(123)
29
- subscription.plan[:interval].should eql("week")
27
+ subscription.offer[:name].should eql("Nerd special")
28
+ subscription.offer[:amount].should eql(123)
29
+ subscription.offer[:interval].should eql("week")
30
30
  subscription.livemode.should be_false
31
31
  subscription.cancel_at_period_end.should be_false
32
32
  subscription.client[:email].should eql("stefan.sprenger@dkd.de")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-09 00:00:00.000000000 Z
12
+ date: 2013-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -52,6 +52,7 @@ extra_rdoc_files: []
52
52
  files:
53
53
  - .gitignore
54
54
  - .rspec
55
+ - .travis.yml
55
56
  - Gemfile
56
57
  - LICENSE
57
58
  - README.md
@@ -99,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
100
  version: '0'
100
101
  segments:
101
102
  - 0
102
- hash: 216517499575340974
103
+ hash: 957344793951118701
103
104
  required_rubygems_version: !ruby/object:Gem::Requirement
104
105
  none: false
105
106
  requirements:
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  version: '0'
109
110
  segments:
110
111
  - 0
111
- hash: 216517499575340974
112
+ hash: 957344793951118701
112
113
  requirements: []
113
114
  rubyforge_project:
114
115
  rubygems_version: 1.8.19