basecrm 1.1.3 → 1.2.0

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: 92229089fcba5bc483cd535b0051c1b8152bcb7e
4
- data.tar.gz: dfcf4b3aff75892ab61169edf258d6ff8a1c7b7e
3
+ metadata.gz: 4e8513fed187fd425dfc03d14f6edc9e0312d5b8
4
+ data.tar.gz: fe357512fa2b8b38d7bd690b74d8dcf8a3aa2278
5
5
  SHA512:
6
- metadata.gz: 3e350b8c9775825b4d5e5ba4e71d8314ad5cad01277ff9382ed693824e79eeedee83286f319cf1c834432c0e74bd91b206472ab7d097fb154ab6a89745f78cba
7
- data.tar.gz: 9e31e4502b094a224624ea90451d19ed392aa3b9bce518f7a6b42dbe42714f7d6bc088ef4128a3746d33422f5352611ba09732e3c10cd4df4d429dcd906446f3
6
+ metadata.gz: 07aefda4c009ce86458520ca4e581d05d5deeea651194c8a8f025a046a0a3edd33f41358ae00a4b59d8a30a76b460d49bcc6beec816946b811fa33de7f9b5819
7
+ data.tar.gz: b24f5704e1bc9c043cb7b59facef478fcbc3088febf54775449a09ab39d56e4ce80498815213e4723b93620a884889e7bc53066abf651e2c083037ca594223cf
data/README.md CHANGED
@@ -93,7 +93,7 @@ client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
93
93
  coffeeshop = client.contacts.where(name: "Coffee Shop")
94
94
 
95
95
  deal = client.deals.create(name: "Website redesign", contact_id: coffeeshop.id)
96
- deal.value = 1000
96
+ deal.value = BigDecimal("1000.99")
97
97
  deal.currency = "USD"
98
98
 
99
99
  client.deals.update(deal) # => BaseCRM::Deal
@@ -202,6 +202,20 @@ Actions:
202
202
  * Update a deal - `client.deals.update`
203
203
  * Delete a deal - `client.deals.destroy`
204
204
 
205
+ **A note about deal value**
206
+
207
+ It is prefered to use a BigDecimal when creating or modyfing a deal value. This guarantees correct precision
208
+
209
+ ```
210
+ deal.value = BigDecimal("1000.98")
211
+ ```
212
+
213
+ You should not be using floats as it may result in precision loss.
214
+
215
+ ```
216
+ deal.value = 1000.98
217
+ ```
218
+
205
219
  ### Lead
206
220
 
207
221
  ```ruby
@@ -7,6 +7,8 @@ require 'basecrm/envelope'
7
7
  require 'basecrm/configuration'
8
8
  require 'basecrm/http_client'
9
9
 
10
+ require 'basecrm/utils/coercion.rb'
11
+
10
12
  require 'basecrm/model'
11
13
  require 'basecrm/models/meta'
12
14
  require 'basecrm/models/account'
@@ -52,7 +52,12 @@ module BaseCRM
52
52
  # @return [Array<String>] An array of tags for a deal. See more at [Tags](/docs/rest/articles/requests#tags).
53
53
  # attr_accessor :tags
54
54
  # @!attribute [rw] value
55
- # @return [Integer] Value of the deal in a currency specified in the `currency` field.
55
+ # @return [BigDecimal] Value of the deal in a currency specified in the `currency` field.
56
56
  # attr_accessor :value
57
+
58
+ def initialize(*args)
59
+ super
60
+ @table[:value] = BaseCRM::Coercion.to_decimal_value(@table[:value] || 0)
61
+ end
57
62
  end
58
63
  end
@@ -131,6 +131,7 @@ module BaseCRM
131
131
  end
132
132
 
133
133
  def sanitize(deal)
134
+ deal.value = Coercion.to_string(deal.value)
134
135
  deal.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
135
136
  end
136
137
  end
@@ -0,0 +1,16 @@
1
+ require "bigdecimal"
2
+
3
+ module BaseCRM
4
+ class Coercion
5
+ def self.to_decimal_value(value)
6
+ BigDecimal.new((value || 0), 15)
7
+ end
8
+
9
+ def self.to_string(value)
10
+ case value
11
+ when BigDecimal then value.to_s('F')
12
+ else value.to_s
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module BaseCRM
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,12 +1,16 @@
1
1
  module ClientHelpers
2
2
  def client
3
- @client ||= BaseCRM::Client.new(access_token: access_token)
3
+ @client ||= BaseCRM::Client.new(access_token: access_token, base_url: base_url)
4
4
  end
5
5
 
6
6
  def access_token
7
7
  @access_token ||= ENV.fetch("BASECRM_ACCESS_TOKEN") { raise '"BASECRM_ACCESS_TOKEN" has not been found.' }
8
8
  end
9
9
 
10
+ def base_url
11
+ @basecrm_url ||= ENV.fetch("BASECRM_BASE_URL") { "https://api.getbase.com" }
12
+ end
13
+
10
14
  def contact
11
15
  @contact ||= FactoryGirl.create(:contact)
12
16
  end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe BaseCRM::Coercion do
4
+ describe "to_decimal" do
5
+ it { expect(BaseCRM::Coercion.to_decimal_value(0)).to eql(0) }
6
+ it { expect(BaseCRM::Coercion.to_decimal_value("0")).to eql(0) }
7
+ it { expect(BaseCRM::Coercion.to_decimal_value(nil)).to eql(0) }
8
+ it { expect(BaseCRM::Coercion.to_decimal_value(1.1)).to eql(BigDecimal.new("1.1", 15)) }
9
+ it { expect(BaseCRM::Coercion.to_decimal_value("1.11")).to eql(BigDecimal.new("1.11", 15)) }
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ require "bigdecimal"
2
+ require "spec_helper"
3
+
4
+ describe BaseCRM::Coercion do
5
+ describe "to_decimal" do
6
+ it { expect(BaseCRM::Coercion.to_decimal_value(0)).to eql(0) }
7
+ it { expect(BaseCRM::Coercion.to_decimal_value("0")).to eql(0) }
8
+ it { expect(BaseCRM::Coercion.to_decimal_value(nil)).to eql(0) }
9
+ it { expect(BaseCRM::Coercion.to_decimal_value(1.1)).to eql(BigDecimal.new("1.1", 15)) }
10
+ it { expect(BaseCRM::Coercion.to_decimal_value("1.11")).to eql(BigDecimal.new("1.11", 15)) }
11
+ end
12
+
13
+ describe "to_string" do
14
+ it { expect(BaseCRM::Coercion.to_string(1)).to eql("1") }
15
+ it { expect(BaseCRM::Coercion.to_string("1")).to eql("1") }
16
+ it { expect(BaseCRM::Coercion.to_string(1.11)).to eql("1.11") }
17
+ it { expect(BaseCRM::Coercion.to_string("1.11")).to eql("1.11") }
18
+ it { expect(BaseCRM::Coercion.to_string(BigDecimal("1.11"))).to eql("1.11") }
19
+ it { expect(BaseCRM::Coercion.to_string(BigDecimal(1.11, 15))).to eql("1.11") }
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basecrm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BaseCRM developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-17 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -171,6 +171,7 @@ files:
171
171
  - lib/basecrm/services/tasks_service.rb
172
172
  - lib/basecrm/services/users_service.rb
173
173
  - lib/basecrm/sync.rb
174
+ - lib/basecrm/utils/coercion.rb
174
175
  - lib/basecrm/version.rb
175
176
  - spec/basecrm/sync_spec.rb
176
177
  - spec/factories/associated_contact.rb
@@ -199,6 +200,8 @@ files:
199
200
  - spec/services/users_service_spec.rb
200
201
  - spec/spec_helper.rb
201
202
  - spec/support/client_helpers.rb
203
+ - spec/utils/coercion.rb
204
+ - spec/utils/coercion_spec.rb
202
205
  homepage: https://github.com/basecrm/basecrm-ruby
203
206
  licenses:
204
207
  - MIT
@@ -219,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
222
  version: '0'
220
223
  requirements: []
221
224
  rubyforge_project:
222
- rubygems_version: 2.4.3
225
+ rubygems_version: 2.2.2
223
226
  signing_key:
224
227
  specification_version: 4
225
228
  summary: BaseCRM Official API V2 library client for ruby
@@ -251,4 +254,6 @@ test_files:
251
254
  - spec/services/users_service_spec.rb
252
255
  - spec/spec_helper.rb
253
256
  - spec/support/client_helpers.rb
257
+ - spec/utils/coercion.rb
258
+ - spec/utils/coercion_spec.rb
254
259
  has_rdoc: