invoiced 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/invoiced/subscription.rb +4 -0
- data/lib/invoiced/version.rb +1 -1
- data/lib/invoiced.rb +2 -4
- data/test/invoiced/SubscriptionTest.rb +85 -0
- data/test/invoiced/customer_test.rb +3 -2
- data/test/invoiced/invoiced_test.rb +2 -2
- metadata +23 -23
- data/lib/invoiced/plan.rb +0 -8
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 739b78cad11f23a94d816a162764b1cc7f4a07e6
         | 
| 4 | 
            +
              data.tar.gz: b81de1a3b758d0552a846dc7f8086446c11d851d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d68a8bf4387dbe7afbd8d48c6dc97f298361aa33ef6b06506bb0d601b322efb18f78e54dc95301191dab6efbbfdc1e1573ebaff31086c41abfd60b63d2f8c208
         | 
| 7 | 
            +
              data.tar.gz: 30321d8b70d9b69aca97bd4db4f4745ec2b428781ca19b6eb7325e079329e3858dcb52ceda91b1b0bb75c0b413a48af1938d2233099157f89425c61b74ed9215
         | 
    
        data/lib/invoiced/version.rb
    CHANGED
    
    
    
        data/lib/invoiced.rb
    CHANGED
    
    | @@ -21,7 +21,6 @@ require 'invoiced/customer' | |
| 21 21 | 
             
            require 'invoiced/email'
         | 
| 22 22 | 
             
            require 'invoiced/invoice'
         | 
| 23 23 | 
             
            require 'invoiced/transaction'
         | 
| 24 | 
            -
            require 'invoiced/plan'
         | 
| 25 24 | 
             
            require 'invoiced/subscription'
         | 
| 26 25 |  | 
| 27 26 | 
             
            module Invoiced
         | 
| @@ -29,19 +28,18 @@ module Invoiced | |
| 29 28 | 
             
            		ApiBase = 'https://api.invoiced.com'
         | 
| 30 29 |  | 
| 31 30 | 
             
            		attr_reader :api_key
         | 
| 32 | 
            -
            		attr_reader :Customer, :Invoice, :Transaction, : | 
| 31 | 
            +
            		attr_reader :Customer, :Invoice, :Transaction, :Subscription
         | 
| 33 32 |  | 
| 34 33 | 
             
            	    def initialize(api_key)
         | 
| 35 34 | 
             
            	      @api_key = api_key
         | 
| 36 35 | 
             
            	      @Customer = Invoiced::Customer.new(self)
         | 
| 37 36 | 
             
            	      @Invoice = Invoiced::Invoice.new(self)
         | 
| 38 37 | 
             
            	      @Transaction = Invoiced::Transaction.new(self)
         | 
| 39 | 
            -
            	      @Plan = Invoiced::Plan.new(self)
         | 
| 40 38 | 
             
            	      @Subscription = Invoiced::Subscription.new(self)
         | 
| 41 39 | 
             
            	    end
         | 
| 42 40 |  | 
| 43 41 | 
             
            	    def request(method, endpoint, params={})
         | 
| 44 | 
            -
            	    	url = ApiBase + endpoint | 
| 42 | 
            +
            	    	url = ApiBase + endpoint
         | 
| 45 43 |  | 
| 46 44 | 
             
            			case method.to_s.downcase.to_sym
         | 
| 47 45 | 
             
            			# These methods don't have a request body
         | 
| @@ -0,0 +1,85 @@ | |
| 1 | 
            +
            require File.expand_path('../../test_helper', __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Invoiced
         | 
| 4 | 
            +
              class SubscriptionTest < Test::Unit::TestCase
         | 
| 5 | 
            +
                should "create a subscription" do
         | 
| 6 | 
            +
                  mockResponse = mock('RestClient::Response')
         | 
| 7 | 
            +
                  mockResponse.stubs(:code).returns(201)
         | 
| 8 | 
            +
                  mockResponse.stubs(:body).returns('{"id":123,"plan":"starter"}')
         | 
| 9 | 
            +
                  mockResponse.stubs(:headers).returns({})
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  subscription = @client.Subscription.create({:customer => 456})
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  assert_instance_of(Invoiced::Subscription, subscription)
         | 
| 16 | 
            +
                  assert_equal(123, subscription.id)
         | 
| 17 | 
            +
                  assert_equal("starter", subscription.plan)
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                should "retrieve a subscription" do
         | 
| 21 | 
            +
                  mockResponse = mock('RestClient::Response')
         | 
| 22 | 
            +
                  mockResponse.stubs(:code).returns(200)
         | 
| 23 | 
            +
                  mockResponse.stubs(:body).returns('{"id":123,"plan":"starter"}')
         | 
| 24 | 
            +
                  mockResponse.stubs(:headers).returns({})
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  subscription = @client.Subscription.retrieve(123)
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  assert_instance_of(Invoiced::Subscription, subscription)
         | 
| 31 | 
            +
                  assert_equal(123, subscription.id)
         | 
| 32 | 
            +
                  assert_equal("starter", subscription.plan)
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                should "not update a subscription when no params" do
         | 
| 36 | 
            +
                  subscription = Subscription.new(@client, 123)
         | 
| 37 | 
            +
                  assert_false(subscription.save)
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                should "update a subscription" do
         | 
| 41 | 
            +
                  mockResponse = mock('RestClient::Response')
         | 
| 42 | 
            +
                  mockResponse.stubs(:code).returns(200)
         | 
| 43 | 
            +
                  mockResponse.stubs(:body).returns('{"id":123,"plan":"pro"}')
         | 
| 44 | 
            +
                  mockResponse.stubs(:headers).returns({})
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  subscription = Subscription.new(@client, 123)
         | 
| 49 | 
            +
                  subscription.plan = "pro"
         | 
| 50 | 
            +
                  assert_true(subscription.save)
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  assert_equal("pro", subscription.plan)
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                should "list all subscriptions" do
         | 
| 56 | 
            +
                  mockResponse = mock('RestClient::Response')
         | 
| 57 | 
            +
                  mockResponse.stubs(:code).returns(200)
         | 
| 58 | 
            +
                  mockResponse.stubs(:body).returns('[{"id":123,"plan":"pro"}]')
         | 
| 59 | 
            +
                  mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/subscriptions?per_page=25&page=1>; rel="self", <https://api.invoiced.com/subscriptions?per_page=25&page=1>; rel="first", <https://api.invoiced.com/subscriptions?per_page=25&page=1>; rel="last"')
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                  subscriptions, metadata = @client.Subscription.list
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  assert_instance_of(Array, subscriptions)
         | 
| 66 | 
            +
                  assert_equal(1, subscriptions.length)
         | 
| 67 | 
            +
                  assert_equal(123, subscriptions[0].id)
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                  assert_instance_of(Invoiced::List, metadata)
         | 
| 70 | 
            +
                  assert_equal(15, metadata.total_count)
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                should "cancel a subscription" do
         | 
| 74 | 
            +
                  mockResponse = mock('RestClient::Response')
         | 
| 75 | 
            +
                  mockResponse.stubs(:code).returns(204)
         | 
| 76 | 
            +
                  mockResponse.stubs(:body).returns('')
         | 
| 77 | 
            +
                  mockResponse.stubs(:headers).returns({})
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                  subscription = Subscription.new(@client, 123)
         | 
| 82 | 
            +
                  assert_true(subscription.cancel)
         | 
| 83 | 
            +
                end
         | 
| 84 | 
            +
              end
         | 
| 85 | 
            +
            end
         | 
| @@ -103,7 +103,7 @@ module Invoiced | |
| 103 103 | 
             
                  mockResponse = mock('RestClient::Response')
         | 
| 104 104 | 
             
                  mockResponse.stubs(:code).returns(200)
         | 
| 105 105 | 
             
                  mockResponse.stubs(:body).returns('{"total_outstanding":1000,"available_credits":0,"past_due":true}')
         | 
| 106 | 
            -
                  mockResponse.stubs(:headers).returns( | 
| 106 | 
            +
                  mockResponse.stubs(:headers).returns({})
         | 
| 107 107 |  | 
| 108 108 | 
             
                  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
         | 
| 109 109 |  | 
| @@ -127,7 +127,8 @@ module Invoiced | |
| 127 127 |  | 
| 128 128 | 
             
                  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
         | 
| 129 129 |  | 
| 130 | 
            -
                   | 
| 130 | 
            +
                  customer = Customer.new(@client, 123)
         | 
| 131 | 
            +
                  subscriptions, metadata = customer.subscriptions
         | 
| 131 132 |  | 
| 132 133 | 
             
                  assert_instance_of(Array, subscriptions)
         | 
| 133 134 | 
             
                  assert_equal(1, subscriptions.length)
         | 
| @@ -19,7 +19,7 @@ module Invoiced | |
| 19 19 | 
             
                  # not used
         | 
| 20 20 | 
             
                  expectedParameters = {
         | 
| 21 21 | 
             
                    :method => "GET",
         | 
| 22 | 
            -
                    :url => "https://api.invoiced.com/invoices? | 
| 22 | 
            +
                    :url => "https://api.invoiced.com/invoices?test=property&filter[levels]=work",
         | 
| 23 23 | 
             
                    :headers => {
         | 
| 24 24 | 
             
                      :authorization => "Basic dGVzdDo=",
         | 
| 25 25 | 
             
                      :content_type => "application/json",
         | 
| @@ -59,7 +59,7 @@ module Invoiced | |
| 59 59 | 
             
                  # not used
         | 
| 60 60 | 
             
                  expectedParameters = {
         | 
| 61 61 | 
             
                    :method => "POST",
         | 
| 62 | 
            -
                    :url => "https://api.invoiced.com/invoices? | 
| 62 | 
            +
                    :url => "https://api.invoiced.com/invoices?test=property&filter[levels]=work",
         | 
| 63 63 | 
             
                    :headers => {
         | 
| 64 64 | 
             
                      :authorization => "Basic dGVzdDo=",
         | 
| 65 65 | 
             
                      :content_type => "application/json",
         | 
    
        metadata
    CHANGED
    
    | @@ -1,111 +1,111 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: invoiced
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0 | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jared King
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-12-04 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rest-client
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - - ~>
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 19 | 
             
                    version: 1.8.0
         | 
| 20 20 | 
             
              type: :runtime
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - - ~>
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: 1.8.0
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: json
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 | 
            -
                - - ~>
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 33 | 
             
                    version: 1.8.3
         | 
| 34 34 | 
             
              type: :runtime
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 | 
            -
                - - ~>
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: 1.8.3
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: activesupport
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 | 
            -
                - - ~>
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 47 | 
             
                    version: 4.2.3
         | 
| 48 48 | 
             
              type: :runtime
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 | 
            -
                - - ~>
         | 
| 52 | 
            +
                - - "~>"
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 54 | 
             
                    version: 4.2.3
         | 
| 55 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 56 | 
             
              name: mocha
         | 
| 57 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 58 | 
             
                requirements:
         | 
| 59 | 
            -
                - - ~>
         | 
| 59 | 
            +
                - - "~>"
         | 
| 60 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 61 | 
             
                    version: 0.13.2
         | 
| 62 62 | 
             
              type: :development
         | 
| 63 63 | 
             
              prerelease: false
         | 
| 64 64 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 65 | 
             
                requirements:
         | 
| 66 | 
            -
                - - ~>
         | 
| 66 | 
            +
                - - "~>"
         | 
| 67 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 68 | 
             
                    version: 0.13.2
         | 
| 69 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 70 | 
             
              name: shoulda
         | 
| 71 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 72 | 
             
                requirements:
         | 
| 73 | 
            -
                - - ~>
         | 
| 73 | 
            +
                - - "~>"
         | 
| 74 74 | 
             
                  - !ruby/object:Gem::Version
         | 
| 75 75 | 
             
                    version: 3.4.0
         | 
| 76 76 | 
             
              type: :development
         | 
| 77 77 | 
             
              prerelease: false
         | 
| 78 78 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 79 | 
             
                requirements:
         | 
| 80 | 
            -
                - - ~>
         | 
| 80 | 
            +
                - - "~>"
         | 
| 81 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| 82 82 | 
             
                    version: 3.4.0
         | 
| 83 83 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 84 84 | 
             
              name: test-unit
         | 
| 85 85 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 86 | 
             
                requirements:
         | 
| 87 | 
            -
                - -  | 
| 87 | 
            +
                - - ">="
         | 
| 88 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 89 | 
             
                    version: '0'
         | 
| 90 90 | 
             
              type: :development
         | 
| 91 91 | 
             
              prerelease: false
         | 
| 92 92 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 93 | 
             
                requirements:
         | 
| 94 | 
            -
                - -  | 
| 94 | 
            +
                - - ">="
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 96 | 
             
                    version: '0'
         | 
| 97 97 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 98 98 | 
             
              name: rake
         | 
| 99 99 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 100 | 
             
                requirements:
         | 
| 101 | 
            -
                - -  | 
| 101 | 
            +
                - - ">="
         | 
| 102 102 | 
             
                  - !ruby/object:Gem::Version
         | 
| 103 103 | 
             
                    version: '0'
         | 
| 104 104 | 
             
              type: :development
         | 
| 105 105 | 
             
              prerelease: false
         | 
| 106 106 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 107 | 
             
                requirements:
         | 
| 108 | 
            -
                - -  | 
| 108 | 
            +
                - - ">="
         | 
| 109 109 | 
             
                  - !ruby/object:Gem::Version
         | 
| 110 110 | 
             
                    version: '0'
         | 
| 111 111 | 
             
            description: Invoiced makes invoicing and recurring billing dead simple
         | 
| @@ -114,8 +114,8 @@ executables: [] | |
| 114 114 | 
             
            extensions: []
         | 
| 115 115 | 
             
            extra_rdoc_files: []
         | 
| 116 116 | 
             
            files:
         | 
| 117 | 
            -
            - .gitignore
         | 
| 118 | 
            -
            - .travis.yml
         | 
| 117 | 
            +
            - ".gitignore"
         | 
| 118 | 
            +
            - ".travis.yml"
         | 
| 119 119 | 
             
            - Gemfile
         | 
| 120 120 | 
             
            - LICENSE
         | 
| 121 121 | 
             
            - README.md
         | 
| @@ -136,11 +136,11 @@ files: | |
| 136 136 | 
             
            - lib/invoiced/operations/delete.rb
         | 
| 137 137 | 
             
            - lib/invoiced/operations/list.rb
         | 
| 138 138 | 
             
            - lib/invoiced/operations/update.rb
         | 
| 139 | 
            -
            - lib/invoiced/plan.rb
         | 
| 140 139 | 
             
            - lib/invoiced/subscription.rb
         | 
| 141 140 | 
             
            - lib/invoiced/transaction.rb
         | 
| 142 141 | 
             
            - lib/invoiced/util.rb
         | 
| 143 142 | 
             
            - lib/invoiced/version.rb
         | 
| 143 | 
            +
            - test/invoiced/SubscriptionTest.rb
         | 
| 144 144 | 
             
            - test/invoiced/customer_test.rb
         | 
| 145 145 | 
             
            - test/invoiced/error_test.rb
         | 
| 146 146 | 
             
            - test/invoiced/invoice_test.rb
         | 
| @@ -159,21 +159,22 @@ require_paths: | |
| 159 159 | 
             
            - lib
         | 
| 160 160 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 161 161 | 
             
              requirements:
         | 
| 162 | 
            -
              - -  | 
| 162 | 
            +
              - - ">="
         | 
| 163 163 | 
             
                - !ruby/object:Gem::Version
         | 
| 164 164 | 
             
                  version: 1.9.3
         | 
| 165 165 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 166 166 | 
             
              requirements:
         | 
| 167 | 
            -
              - -  | 
| 167 | 
            +
              - - ">="
         | 
| 168 168 | 
             
                - !ruby/object:Gem::Version
         | 
| 169 169 | 
             
                  version: '0'
         | 
| 170 170 | 
             
            requirements: []
         | 
| 171 171 | 
             
            rubyforge_project: 
         | 
| 172 | 
            -
            rubygems_version: 2. | 
| 172 | 
            +
            rubygems_version: 2.2.2
         | 
| 173 173 | 
             
            signing_key: 
         | 
| 174 174 | 
             
            specification_version: 4
         | 
| 175 175 | 
             
            summary: Ruby client library for the Invoiced API
         | 
| 176 176 | 
             
            test_files:
         | 
| 177 | 
            +
            - test/invoiced/SubscriptionTest.rb
         | 
| 177 178 | 
             
            - test/invoiced/customer_test.rb
         | 
| 178 179 | 
             
            - test/invoiced/error_test.rb
         | 
| 179 180 | 
             
            - test/invoiced/invoice_test.rb
         | 
| @@ -182,4 +183,3 @@ test_files: | |
| 182 183 | 
             
            - test/invoiced/transaction_test.rb
         | 
| 183 184 | 
             
            - test/invoiced/util_test.rb
         | 
| 184 185 | 
             
            - test/test_helper.rb
         | 
| 185 | 
            -
            has_rdoc: 
         |