freshbooks.rb 3.0.16 → 3.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -60,7 +60,7 @@ require 'logger'
60
60
  #
61
61
  #==============================================================================
62
62
  module FreshBooks
63
- VERSION = '3.0.16' # Gem version
63
+ VERSION = '3.0.17' # Gem version
64
64
  API_VERSION = '2.1' # FreshBooks API version
65
65
  SERVICE_URL = "/api/#{API_VERSION}/xml-in"
66
66
 
@@ -4,7 +4,7 @@ require 'logger'
4
4
 
5
5
  module FreshBooks
6
6
  class Connection
7
- attr_reader :account_url, :auth_token, :request_headers
7
+ attr_reader :account_url, :auth_token, :utc_offset, :request_headers
8
8
 
9
9
  @@logger = Logger.new(STDOUT)
10
10
  def logger
@@ -16,13 +16,13 @@ module FreshBooks
16
16
  end
17
17
  self.log_level = Logger::WARN
18
18
 
19
- def initialize(account_url, auth_token, request_headers = {})
19
+ def initialize(account_url, auth_token, request_headers = {}, options = {})
20
20
  raise InvalidAccountUrlError.new unless account_url =~ /^[0-9a-zA-Z\-_]+\.freshbooks\.com$/
21
21
 
22
22
  @account_url = account_url
23
23
  @auth_token = auth_token
24
24
  @request_headers = request_headers
25
-
25
+ @utc_offset = options[:utc_offset] || -4
26
26
  @start_session_count = 0
27
27
  end
28
28
 
@@ -96,16 +96,21 @@ module FreshBooks
96
96
  class DateTimeSerializer
97
97
  def self.to_node(member_name, value)
98
98
  element = REXML::Element.new(member_name)
99
- element.text = (value.utc - 4.hours).to_s(:db) # hack to convert to gmt-4, any better way?
99
+ element.text = (value.utc + time_offset.to_i.hours).to_s(:db) # hack to convert to gmt-4, any better way?
100
100
  element
101
101
  end
102
102
 
103
103
  def self.to_value(xml_val)
104
- DateTime.parse(xml_val.text.to_s + " -04:00").utc # hack to convert from gmt-4 to utc
104
+ DateTime.parse(xml_val.text.to_s + " #{time_offset}").utc # hack to convert from gmt-4 to utc
105
105
  rescue ArgumentError => e
106
106
  # Sometimes freshbooks gives dates that look like this 0000-00-00 00:00:00
107
107
  nil
108
108
  end
109
+
110
+ private
111
+ def self.time_offset
112
+ ENV['FRESHBOOKS_TIMEZONE'] || "-04:00"
113
+ end
109
114
  end
110
115
  end
111
116
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freshbooks.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.16
4
+ version: 3.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Curren
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-27 00:00:00 -06:00
12
+ date: 2009-11-01 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency