paymo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad2c072b47426d2a8da6501f38703c59fad6a4bb
4
- data.tar.gz: 6b56a49fd6dd88349faea16821f813b1cdbf1cd6
3
+ metadata.gz: 1c6436a9964cb7900b965e0e3f0250c1605d733d
4
+ data.tar.gz: 10f216a798381d4f9087bed49ce9eda9f08ed2bf
5
5
  SHA512:
6
- metadata.gz: b2101e12090c4990898f7fbc17a6c634fd171e0dbe85a79bbbe3dc5c78294aaa1292271a0d55304622d70eb982357971e5492eb709deb730c468f641eb632887
7
- data.tar.gz: c61e8cc503a6b887d2a482f6cbcadcc8ad1c334fcb0188a033a69fe0914c2020486a3200d617710593dcc964112d8d435330f9a27e6c52c7f2ffdf6786cb6042
6
+ metadata.gz: 714cdad6feb0dcbbda3d277b65f69cf607263d532c14123a09a5c902e00aa9cf580890a05aaa6228c2b0f279fb58d9e44b78d8e0c047696ef9cfead56e7c7652
7
+ data.tar.gz: 5f044f1860e951cee72a70b598cc2f09d9d5e0fc712deb8cd9c62bede86837daf106bb86a04790142870c657c2453e3bbc3e61fd31b2be515b2594b0fe9f06ef
@@ -12,21 +12,22 @@ module Paymo
12
12
  API_ENDPOINT = 'https://api.paymo.biz/service/'
13
13
 
14
14
  class << self
15
+ attr_accessor :config
16
+ end
15
17
 
16
- attr_writer :auth_token, :debug
17
-
18
- def api_key
19
- ENV['PAYMO_API_KEY']
20
- end
18
+ def self.configure
19
+ self.config ||= Configuration.new
20
+ yield(config)
21
+ end
21
22
 
22
- def auth_token
23
- @auth_token ||= ''
24
- end
23
+ class Configuration
24
+ attr_accessor :api_key, :debug, :auth_token
25
25
 
26
- def debug
27
- @debug ||= false
26
+ def initialize
27
+ @api_key = ENV['PAYMO_API_KEY']
28
+ @debug = false
29
+ @auth_token = nil
28
30
  end
29
-
30
31
  end
31
32
 
32
33
  class Base
@@ -43,10 +44,10 @@ module Paymo
43
44
  format: @format,
44
45
  username: @username,
45
46
  password: @password,
46
- api_key: Paymo.api_key
47
+ api_key: Paymo.config.api_key
47
48
  }
48
49
  # add error checking
49
- Paymo.auth_token = response['token']['_content']
50
+ Paymo.config.auth_token = response['token']['_content']
50
51
  end
51
52
 
52
53
  end
@@ -8,18 +8,18 @@ module Paymo
8
8
 
9
9
  def self.get(resource, method, options = {})
10
10
  method = methodize(resource, method)
11
- options.merge!({ auth_token: Paymo.auth_token, api_key: Paymo.api_key, format: 'json' })
12
- puts "curl #{API_ENDPOINT}paymo.#{method}?#{URI.encode_www_form(options)}" if Paymo.debug
11
+ options.merge!({ auth_token: Paymo.config.auth_token, api_key: Paymo.config.api_key, format: 'json' })
12
+ puts "curl #{API_ENDPOINT}paymo.#{method}?#{URI.encode_www_form(options)}" if Paymo.config.debug
13
13
  json = RestClient.get "#{API_ENDPOINT}paymo.#{method}", { params: options }
14
14
  JSON.parse(json)
15
15
  end
16
16
 
17
17
  def self.post(resource, method, options = {})
18
18
  method = methodize(resource, method)
19
- options.merge!({ auth_token: Paymo.auth_token, api_key: Paymo.api_key, format: 'json' })
20
- puts "curl -X POST -d '#{URI.encode_www_form(options)}' #{API_ENDPOINT}paymo.#{method}" if Paymo.debug
19
+ options.merge!({ auth_token: Paymo.config.auth_token, api_key: Paymo.config.api_key, format: 'json' })
20
+ puts "curl -X POST -d '#{URI.encode_www_form(options)}' #{API_ENDPOINT}paymo.#{method}" if Paymo.config.debug
21
21
  json = RestClient.post "#{API_ENDPOINT}paymo.#{method}", options
22
22
  JSON.parse(json)
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Paymo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Paymo do
4
+ describe '#configure' do
5
+ it 'hands API configuration to the gem' do
6
+ Paymo.configure do |config|
7
+ config.api_key = ENV['PAYMO_API_KEY']
8
+ end
9
+ Paymo.config.api_key.should be_a String
10
+ end
11
+ end
12
+ end
@@ -13,3 +13,7 @@ VCR.configure do |c|
13
13
  c.cassette_library_dir = 'fixtures/vcr_cassettes'
14
14
  c.hook_into :webmock
15
15
  end
16
+
17
+ Paymo.configure do |config|
18
+ config.api_key = ENV['PAYMO_API_KEY']
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Duncombe
@@ -53,6 +53,7 @@ files:
53
53
  - spec/lib/paymo/resources/entries_spec.rb
54
54
  - spec/lib/paymo/resources/projects_spec.rb
55
55
  - spec/lib/paymo/resources/reports_spec.rb
56
+ - spec/lib/paymo_spec.rb
56
57
  - spec/spec_helper.rb
57
58
  homepage: https://github.com/jamesduncombe/paymo
58
59
  licenses:
@@ -84,4 +85,5 @@ test_files:
84
85
  - spec/lib/paymo/resources/entries_spec.rb
85
86
  - spec/lib/paymo/resources/projects_spec.rb
86
87
  - spec/lib/paymo/resources/reports_spec.rb
88
+ - spec/lib/paymo_spec.rb
87
89
  - spec/spec_helper.rb