pipedriver 0.0.3 → 0.0.4

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.
@@ -0,0 +1,19 @@
1
+ module Pipedriver
2
+ class Client
3
+
4
+ # Define the same set of accessors as the Pipedriver module
5
+ attr_accessor *Configuration::VALID_CONFIG_KEYS
6
+
7
+ def initialize(options={})
8
+ # Merge the config values from the module and those passed
9
+ # to the client.
10
+ merged_options = Pipedriver.options.merge(options)
11
+
12
+ # Copy the merged values to this client and ignore those
13
+ # not part of our configuration
14
+ Configuration::VALID_CONFIG_KEYS.each do |key|
15
+ send("#{key}=", merged_options[key])
16
+ end
17
+ end
18
+ end # Client
19
+ end
@@ -0,0 +1,42 @@
1
+ module Pipedriver
2
+ module Configuration
3
+ VALID_CONNECTION_KEYS = [:endpoint, :user_agent, :method].freeze
4
+ VALID_OPTIONS_KEYS = [:api_key, :format].freeze
5
+ VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
6
+
7
+ DEFAULT_ENDPOINT = 'https://api.pipedrive.com/v1'
8
+ DEFAULT_METHOD = :get
9
+ DEFAULT_USER_AGENT = "Pipedriver API Ruby Gem #{Pipedriver::VERSION}".freeze
10
+
11
+ DEFAULT_API_KEY = nil
12
+ DEFAULT_FORMAT = :json
13
+
14
+ # Build accessor methods for every config options so we can do this, for example:
15
+ # Pipedrive.format = :xml
16
+ attr_accessor *VALID_CONFIG_KEYS
17
+
18
+ # Make sure we have the default values set when we get 'extended'
19
+ def self.extended(base)
20
+ base.reset
21
+ end
22
+
23
+ def reset
24
+ self.endpoint = DEFAULT_ENDPOINT
25
+ self.method = DEFAULT_METHOD
26
+ self.user_agent = DEFAULT_USER_AGENT
27
+
28
+ self.api_key = DEFAULT_API_KEY
29
+ self.format = DEFAULT_FORMAT
30
+ end
31
+
32
+ def configure
33
+ yield self
34
+ end
35
+
36
+ # Return the configuration values set in this module
37
+ def options
38
+ Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ]
39
+ end
40
+
41
+ end # Configuration
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Pipedriver
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/pipedriver.gemspec CHANGED
@@ -1,5 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
  require 'pipedriver/version'
4
5
 
5
6
  Gem::Specification.new do |gem|
data/test/helper.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'pipedriver'
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
@@ -0,0 +1,60 @@
1
+ require 'helper'
2
+
3
+ describe Pipedriver::Client do
4
+
5
+ before do
6
+ @keys = Pipedriver::Configuration::VALID_CONFIG_KEYS
7
+ end
8
+
9
+ describe 'with module configuration' do
10
+ before do
11
+ Pipedriver.configure do |config|
12
+ @keys.each do |key|
13
+ config.send("#{key}=", key)
14
+ end
15
+ end
16
+ end
17
+
18
+ after do
19
+ Pipedriver.reset
20
+ end
21
+
22
+ it "should inherit module configuration" do
23
+ api = Pipedriver::Client.new
24
+ @keys.each do |key|
25
+ api.send(key).must_equal key
26
+ end
27
+ end
28
+
29
+ describe 'with class configuration' do
30
+ before do
31
+ @config = {
32
+ :api_key => 'ak',
33
+ :format => 'of',
34
+ :endpoint => 'ep',
35
+ :user_agent => 'ua',
36
+ :method => 'hm',
37
+ }
38
+ end
39
+
40
+ it 'should override module configuration' do
41
+ api = Pipedriver::Client.new(@config)
42
+ @keys.each do |key|
43
+ api.send(key).must_equal @config[key]
44
+ end
45
+ end
46
+
47
+ it 'should override module configuration after' do
48
+ api = Pipedriver::Client.new
49
+
50
+ @config.each do |key, value|
51
+ api.send("#{key}=", value)
52
+ end
53
+
54
+ @keys.each do |key|
55
+ api.send("#{key}").must_equal @config[key]
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,27 @@
1
+ require 'helper'
2
+
3
+ describe 'configuration' do
4
+
5
+ after do
6
+ Pipedriver.reset
7
+ end
8
+
9
+ describe '.configure' do
10
+ Pipedriver::Configuration::VALID_CONFIG_KEYS.each do |key|
11
+ it "should set the #{key}" do
12
+ Pipedriver.configure do |config|
13
+ config.send("#{key}=", key)
14
+ Pipedriver.send(key).must_equal key
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ Pipedriver::Configuration::VALID_CONFIG_KEYS.each do |key|
21
+ describe ".#{key}" do
22
+ it 'should return the default value' do
23
+ Pipedriver.send(key).must_equal Pipedriver::Configuration.const_get("DEFAULT_#{key.upcase}")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ describe Pipedriver do
4
+ it 'should have a version' do
5
+ Pipedriver::VERSION.wont_be_nil
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipedriver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -88,8 +88,14 @@ files:
88
88
  - README.md
89
89
  - Rakefile
90
90
  - lib/pipedriver.rb
91
+ - lib/pipedriver/client.rb
92
+ - lib/pipedriver/configuration.rb
91
93
  - lib/pipedriver/version.rb
92
94
  - pipedriver.gemspec
95
+ - test/helper.rb
96
+ - test/pipedriver/client_test.rb
97
+ - test/pipedriver/configuration_test.rb
98
+ - test/pipedriver/pipedrive_test.rb
93
99
  homepage: ''
94
100
  licenses: []
95
101
  post_install_message:
@@ -114,4 +120,8 @@ rubygems_version: 1.8.24
114
120
  signing_key:
115
121
  specification_version: 3
116
122
  summary: A gem to wrap the pipedrive API
117
- test_files: []
123
+ test_files:
124
+ - test/helper.rb
125
+ - test/pipedriver/client_test.rb
126
+ - test/pipedriver/configuration_test.rb
127
+ - test/pipedriver/pipedrive_test.rb