pipedrive-ruby 0.2.4 → 0.2.5

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.
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ Jeweler::Tasks.new do |gem|
20
20
  gem.summary = %Q{Ruby wrapper for the Pipedrive API}
21
21
  gem.description = %Q{Ruby wrapper for the Pipedrive API}
22
22
  gem.email = "jan@general-scripting.com"
23
- gem.authors = ["Waldemar Kusnezow", "Jan Schwenzien", "Patrick Kozma"]
23
+ gem.authors = ["Jan Schwenzien", "Waldemar Kusnezow"]
24
24
  # dependencies defined in Gemfile
25
25
  end
26
26
  Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.5
@@ -2,6 +2,7 @@ require 'pipedrive/base'
2
2
  require 'pipedrive/deal'
3
3
  require 'pipedrive/organization'
4
4
  require 'pipedrive/person'
5
+ require 'pipedrive/product'
5
6
 
6
7
  module Pipedrive
7
8
 
@@ -1,45 +1,26 @@
1
1
  require 'httparty'
2
2
  require 'ostruct'
3
+ require 'forwardable'
3
4
 
4
5
  module Pipedrive
5
-
6
+
6
7
  # Globally set request headers
7
8
  HEADERS = {
8
9
  "User-Agent" => "Ruby.Pipedrive.Api",
9
10
  "Accept" => "application/json",
10
11
  "Content-Type" => "application/x-www-form-urlencoded"
11
12
  }
12
-
13
+
13
14
  # Base class for setting HTTParty configurations globally
14
15
  class Base < OpenStruct
15
-
16
+
16
17
  include HTTParty
17
18
  base_uri 'api.pipedrive.com/v1'
18
19
  headers HEADERS
19
20
  format :json
20
-
21
- # Sets the authentication credentials in a class variable.
22
- #
23
- # @param [String] email cl.ly email
24
- # @param [String] password cl.ly password
25
- # @return [Hash] authentication credentials
26
- def self.authenticate(token)
27
- self.default_params :api_token => token
28
- end
29
-
30
- # Examines a bad response and raises an approriate exception
31
- #
32
- # @param [HTTParty::Response] response
33
- def self.bad_response(response)
34
- if response.class == HTTParty::Response
35
- raise ResponseError, response
36
- end
37
- raise StandardError, "Unkown error"
38
- end
39
21
 
40
- def self.new_list( attrs )
41
- attrs['data'].is_a?(Array) ? attrs['data'].map {|data| self.new( 'data' => data ) } : []
42
- end
22
+ extend Forwardable
23
+ def_delegators 'self.class', :get, :post, :put, :resource_path, :bad_response
43
24
 
44
25
  attr_reader :data
45
26
 
@@ -50,9 +31,86 @@ module Pipedrive
50
31
  # @param [Hash] attributes
51
32
  # @return [CloudApp::Base]
52
33
  def initialize(attrs = {})
53
- super( attrs['data'] )
34
+ if attrs['data']
35
+ super( attrs['data'] )
36
+ else
37
+ super(attrs)
38
+ end
39
+ end
40
+
41
+ # Updates the object.
42
+ #
43
+ # @param [Hash] opts
44
+ # @return [Boolean]
45
+ def update(opts = {})
46
+ res = put "#{resource_path}/#{id}", :body => opts
47
+ !!(res.success? && @table.merge!(res['data'].symbolize_keys))
48
+ end
49
+
50
+ class << self
51
+ # Sets the authentication credentials in a class variable.
52
+ #
53
+ # @param [String] email cl.ly email
54
+ # @param [String] password cl.ly password
55
+ # @return [Hash] authentication credentials
56
+ def authenticate(token)
57
+ default_params :api_token => token
58
+ end
59
+
60
+ # Examines a bad response and raises an appropriate exception
61
+ #
62
+ # @param [HTTParty::Response] response
63
+ def bad_response(response)
64
+ if response.class == HTTParty::Response
65
+ raise HTTParty::ResponseError, response
66
+ end
67
+ raise StandardError, 'Unknown error'
68
+ end
69
+
70
+ def new_list( attrs )
71
+ attrs['data'].is_a?(Array) ? attrs['data'].map {|data| self.new( 'data' => data ) } : []
72
+ end
73
+
74
+ def all(response = nil)
75
+ res = response || get(resource_path)
76
+ if res.ok?
77
+ res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
78
+ else
79
+ bad_response(res)
80
+ end
81
+ end
82
+
83
+ def create( opts = {} )
84
+ res = post resource_path, :body => opts
85
+ if res.success?
86
+ res['data'] = opts.merge res['data']
87
+ new(res)
88
+ else
89
+ bad_response(res)
90
+ end
91
+ end
92
+
93
+ def find(id)
94
+ res = get "#{resource_path}/#{id}"
95
+ res.ok? ? new(res) : bad_response(res)
96
+ end
97
+
98
+ def find_by_name(name, opts={})
99
+ res = get "#{resource_path}/find", :query => { :term => name }.merge(opts)
100
+ res.ok? ? new_list(res) : bad_response(res)
101
+ end
102
+
103
+ def resource_path
104
+ "/#{name.split('::').last.downcase}s"
105
+ end
54
106
  end
55
-
56
- end
57
-
107
+
108
+ # TODO Rewrite this.
109
+ module Deals
110
+ def deals
111
+ Deal.all(get "#{resource_path}/#{id}/deals")
112
+ end
113
+ end
114
+ end
115
+
58
116
  end
@@ -1,26 +1,10 @@
1
1
  module Pipedrive
2
-
3
2
  class Deal < Base
4
3
 
5
- def self.create( opts = {} )
6
- res = post "/deals", :body => opts
7
- if res.success?
8
- res['data'] = opts.merge res['data']
9
- Deal.new(res)
10
- else
11
- bad_response(res)
12
- end
13
- end
14
-
15
- def self.find(id)
16
- res = get "/deals/#{id}"
17
- if res.ok?
18
- Deal.new(res)
19
- else
20
- bad_response(res)
21
- end
4
+ def add_product(opts = {})
5
+ res = post "#{resource_path}/#{id}/products", :body => opts
6
+ res.success? ? res['data']['product_attachment_id'] : bad_response(res)
22
7
  end
23
8
 
24
9
  end
25
-
26
10
  end
@@ -1,39 +1,18 @@
1
1
  module Pipedrive
2
-
3
2
  class Organization < Base
3
+ include Deals
4
4
 
5
- def self.create( opts = {} )
6
- res = post "/organizations", :body => opts
7
- if res.success?
8
- res['data'] = opts.merge res['data']
9
- Organization.new(res)
10
- else
11
- bad_response(res)
12
- end
5
+ # TODO Rewrite this.
6
+ def persons
7
+ Person.all(get "#{resource_path}/#{id}/persons")
13
8
  end
14
9
 
15
- def self.find_or_create_by_name( name, opts={} )
16
- find_by_name( name ).first || create( opts.merge( :title => name ) )
17
- end
10
+ class << self
18
11
 
19
- def self.find(id)
20
- res = get "/organizations/#{id}"
21
- if res.ok?
22
- Organization.new(res)
23
- else
24
- bad_response(res)
12
+ def find_or_create_by_name(name, opts={})
13
+ find_by_name(name).first || create(opts.merge(:title => name))
25
14
  end
26
- end
27
15
 
28
- def self.find_by_name(name, opts={})
29
- res = get "/organizations/find", :query => { :term => name }.merge(opts)
30
- if res.ok?
31
- Organization.new_list(res)
32
- else
33
- bad_response(res)
34
- end
35
16
  end
36
-
37
17
  end
38
-
39
18
  end
@@ -1,39 +1,12 @@
1
1
  module Pipedrive
2
-
3
2
  class Person < Base
4
3
 
5
- def self.create( opts = {} )
6
- res = post "/persons", :body => opts
7
- if res.success?
8
- res['data'] = opts.merge res['data']
9
- Person.new(res)
10
- else
11
- bad_response(res)
12
- end
13
- end
14
-
15
- def self.find_or_create_by_name( name, opts={} )
16
- find_by_name( name, :org_id => opts[:org_id] ).first || create( opts.merge( :name => name ) )
17
- end
4
+ class << self
18
5
 
19
- def self.find(id)
20
- res = get "/persons/#{id}"
21
- if res.ok?
22
- Person.new(res)
23
- else
24
- bad_response(res)
6
+ def find_or_create_by_name(name, opts={})
7
+ find_by_name(name, :org_id => opts[:org_id]).first || create(opts.merge(:name => name))
25
8
  end
26
- end
27
9
 
28
- def self.find_by_name(name, opts={})
29
- res = get "/persons/find", :query => { :term => name }.merge(opts)
30
- if res.ok?
31
- Person.new_list(res)
32
- else
33
- bad_response(res)
34
- end
35
10
  end
36
-
37
11
  end
38
-
39
12
  end
@@ -0,0 +1,6 @@
1
+ module Pipedrive
2
+ class Product < Base
3
+ include Deals
4
+
5
+ end
6
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "pipedrive-ruby"
8
- s.version = "0.2.4"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Waldemar Kusnezow", "Jan Schwenzien", "Patrick Kozma"]
12
- s.date = "2012-11-06"
11
+ s.authors = ["Jan Schwenzien", "Waldemar Kusnezow"]
12
+ s.date = "2013-02-09"
13
13
  s.description = "Ruby wrapper for the Pipedrive API"
14
14
  s.email = "jan@general-scripting.com"
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "lib/pipedrive/deal.rb",
28
28
  "lib/pipedrive/organization.rb",
29
29
  "lib/pipedrive/person.rb",
30
+ "lib/pipedrive/product.rb",
30
31
  "pipedrive-ruby.gemspec",
31
32
  "test/helper.rb",
32
33
  "test/test_pipedrive-rails.rb"
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipedrive-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Waldemar Kusnezow
9
8
  - Jan Schwenzien
10
- - Patrick Kozma
9
+ - Waldemar Kusnezow
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2012-11-06 00:00:00.000000000 Z
13
+ date: 2013-02-09 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: httparty
@@ -127,6 +126,7 @@ files:
127
126
  - lib/pipedrive/deal.rb
128
127
  - lib/pipedrive/organization.rb
129
128
  - lib/pipedrive/person.rb
129
+ - lib/pipedrive/product.rb
130
130
  - pipedrive-ruby.gemspec
131
131
  - test/helper.rb
132
132
  - test/test_pipedrive-rails.rb
@@ -145,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  segments:
147
147
  - 0
148
- hash: 3219907950570205056
148
+ hash: -526297699486921758
149
149
  required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements: