quickeebooks 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md ADDED
@@ -0,0 +1,7 @@
1
+ ## 0.1.0 (2013-01-16)
2
+
3
+ * Quickbooks Online now supports a single HTTP endpoint for API calls, no need to first determine the Base URL. `Quickeebooks::Online::ServiceBase` has been adjusted to use a single API endpoint.
4
+
5
+ ## < 0.0.9
6
+
7
+ History was not being tracked so there is no changelog of activity before `0.0.9`
@@ -19,14 +19,14 @@ module Quickeebooks
19
19
  attr_accessor :oauth
20
20
  attr_accessor :base_uri
21
21
 
22
- QB_BASE_URI = "https://qbo.intuit.com/qbo1/rest/user/v2"
22
+ QB_BASE_URI = "https://qbo.sbfinance.intuit.com"
23
23
  XML_NS = %{xmlns:ns2="http://www.intuit.com/sb/cdm/qbo" xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:ns3="http://www.intuit.com/sb/cdm"}
24
24
 
25
25
  def initialize(oauth_access_token = nil, realm_id = nil)
26
26
  if !oauth_access_token.nil? && !realm_id.nil?
27
27
  msg = "Quickeebooks::Online::ServiceBase - "
28
28
  msg += "This version of the constructor is deprecated. "
29
- msg += "Use the no-arg constructor and set the AccessToken and the RealmID using the accessors."
29
+ msg += "Use the no-arg constructor and set the AccessToken (access_token=) and the RealmID (realm_id=) using the setters."
30
30
  warn(msg)
31
31
  access_token = oauth_access_token
32
32
  realm_id = realm_id
@@ -46,61 +46,29 @@ module Quickeebooks
46
46
  @base_uri = uri
47
47
  end
48
48
 
49
- # Given a realm ID we need to determine the real Base URL
50
- # to use for all subsequenet REST operations
51
- # See: https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0050_Data_Services/0400_QuickBooks_Online/0100_Calling_Data_Services/0010_Getting_the_Base_URL
52
- def determine_base_url
53
- if service_response
54
- if service_response.code == "200"
55
- element = base_doc.xpath("//qbo:QboUser/qbo:CurrentCompany/qbo:BaseURI")[0]
56
- if element
57
- @base_uri = element.text
58
- else
59
- raise IntuitRequestException.new("Response error: Could not extract BaseURI from response. Invalid XML: #{service_response.body}")
60
- end
61
- else
62
- raise IntuitRequestException.new("Response error: invalid code #{service_response.code}")
63
- end
64
- end
65
- end
66
-
67
49
  def url_for_resource(resource)
68
50
  url_for_base("resource/#{resource}")
69
51
  end
70
52
 
71
53
  def url_for_base(raw)
72
- determine_base_url unless determined_base_url?
73
- "#{@base_uri}/#{raw}/v2/#{@realm_id}"
74
- end
75
-
76
- def qb_base_uri_with_realm_id
77
- "#{QB_BASE_URI}/#{@realm_id}"
78
- end
79
-
80
- # store service base response
81
- # so it can be accessed by other methods
82
- def service_response
83
- @service_response ||= check_response(@oauth.request(:get, qb_base_uri_with_realm_id))
54
+ "#{QB_BASE_URI}/#{raw}/v2/#{@realm_id}"
84
55
  end
85
56
 
86
- # allows for reuse of service base's xml doc
87
- # rather than loading it each time we need it
88
- def base_doc
89
- @base_doc ||= parse_xml(service_response.body)
90
- end
91
-
92
57
  # gives us the qbo user's LoginName
93
58
  # useful for verifying email address against
94
59
  def login_name
95
- @login_name ||= base_doc.xpath("//qbo:QboUser/qbo:LoginName")[0].text
60
+ @login_name ||= begin
61
+ url = "https://qbo.intuit.com/qbo1/rest/user/v2/#{@realm_id}"
62
+ response = @oauth.request(:get, url)
63
+ if response && response.code.to_i == 200
64
+ xml = parse_xml(response.body)
65
+ xml.xpath("//qbo:QboUser/qbo:LoginName")[0].text
66
+ end
67
+ end
96
68
  end
97
69
 
98
70
  private
99
71
 
100
- def determined_base_url?
101
- @base_uri != nil
102
- end
103
-
104
72
  def parse_xml(xml)
105
73
  Nokogiri::XML(xml)
106
74
  end
@@ -112,8 +80,6 @@ module Quickeebooks
112
80
  def fetch_collection(model, filters = [], page = 1, per_page = 20, sort = nil, options ={})
113
81
  raise ArgumentError, "missing model to instantiate" if model.nil?
114
82
 
115
- determine_base_url unless determined_base_url?
116
-
117
83
  post_body_lines = []
118
84
 
119
85
  if filters.is_a?(Array) && filters.length > 0
@@ -167,7 +133,6 @@ module Quickeebooks
167
133
  unless headers.has_key?('Content-Type')
168
134
  headers.merge!({'Content-Type' => 'application/xml'})
169
135
  end
170
- determine_base_url unless determined_base_url?
171
136
  # puts "METHOD = #{method}"
172
137
  # puts "URL = #{url}"
173
138
  # puts "BODY = #{body == nil ? "<NIL>" : body}"
@@ -1,5 +1,5 @@
1
1
  module Quickeebooks
2
2
 
3
- VERSION = "0.0.9"
3
+ VERSION = "0.1.0"
4
4
 
5
5
  end
@@ -10,7 +10,6 @@ describe "Quickeebooks::Online::Service::Account" do
10
10
  qb_secret = "secreet"
11
11
 
12
12
  @realm_id = "9991111222"
13
- @base_uri = "https://qbo.intuit.com/qbo36"
14
13
  @oauth_consumer = OAuth::Consumer.new(qb_key, qb_key, {
15
14
  :site => "https://oauth.intuit.com",
16
15
  :request_token_path => "/oauth/v1/get_request_token",
@@ -24,10 +23,6 @@ describe "Quickeebooks::Online::Service::Account" do
24
23
  @service.instance_eval {
25
24
  @realm_id = "9991111222"
26
25
  }
27
- @service.base_uri = @base_uri
28
- determine_base_url = @service.qb_base_uri_with_realm_id
29
- xml = File.read(File.dirname(__FILE__) + "/../../../xml/online/determine_base_url.xml")
30
- FakeWeb.register_uri(:get, determine_base_url, :status => ["200", "OK"], :body => xml)
31
26
  end
32
27
 
33
28
  it "receives 404 from invalid base URL" do
@@ -10,7 +10,6 @@ describe "Quickeebooks::Online::Service::CompanyMetaData" do
10
10
  qb_secret = "secreet"
11
11
 
12
12
  @realm_id = "9991111222"
13
- @base_uri = "https://qbo.intuit.com/qbo36"
14
13
  @oauth_consumer = OAuth::Consumer.new(qb_key, qb_key, {
15
14
  :site => "https://oauth.intuit.com",
16
15
  :request_token_path => "/oauth/v1/get_request_token",
@@ -24,10 +23,6 @@ describe "Quickeebooks::Online::Service::CompanyMetaData" do
24
23
  @service.instance_eval {
25
24
  @realm_id = "9991111222"
26
25
  }
27
- @service.base_uri = @base_uri
28
- determine_base_url = @service.qb_base_uri_with_realm_id
29
- xml = File.read(File.dirname(__FILE__) + "/../../../xml/online/determine_base_url.xml")
30
- FakeWeb.register_uri(:get, determine_base_url, :status => ["200", "OK"], :body => xml)
31
26
  end
32
27
 
33
28
  it "can get the realm's company_meta_data record" do
@@ -10,7 +10,6 @@ describe "Quickeebooks::Online::Service::Customer" do
10
10
  qb_secret = "secreet"
11
11
 
12
12
  @realm_id = "9991111222"
13
- @base_uri = "https://qbo.intuit.com/qbo36"
14
13
  @oauth_consumer = OAuth::Consumer.new(qb_key, qb_key, {
15
14
  :site => "https://oauth.intuit.com",
16
15
  :request_token_path => "/oauth/v1/get_request_token",
@@ -24,10 +23,6 @@ describe "Quickeebooks::Online::Service::Customer" do
24
23
  @service.instance_eval {
25
24
  @realm_id = "9991111222"
26
25
  }
27
- @service.base_uri = @base_uri
28
- determine_base_url = @service.qb_base_uri_with_realm_id
29
- xml = File.read(File.dirname(__FILE__) + "/../../../xml/online/determine_base_url.xml")
30
- FakeWeb.register_uri(:get, determine_base_url, :status => ["200", "OK"], :body => xml)
31
26
  end
32
27
 
33
28
  it "can fetch a list of customers" do
@@ -10,7 +10,6 @@ describe "Quickeebooks::Online::Service::Invoice" do
10
10
  qb_secret = "secreet"
11
11
 
12
12
  @realm_id = "9991111222"
13
- @base_uri = "https://qbo.intuit.com/qbo36"
14
13
  @oauth_consumer = OAuth::Consumer.new(qb_key, qb_key, {
15
14
  :site => "https://oauth.intuit.com",
16
15
  :request_token_path => "/oauth/v1/get_request_token",
@@ -23,10 +22,6 @@ describe "Quickeebooks::Online::Service::Invoice" do
23
22
  @service.instance_eval {
24
23
  @realm_id = "9991111222"
25
24
  }
26
- @service.base_uri = @base_uri
27
- determine_base_url = @service.qb_base_uri_with_realm_id
28
- xml = File.read(File.dirname(__FILE__) + "/../../../xml/online/determine_base_url.xml")
29
- FakeWeb.register_uri(:get, determine_base_url, :status => ["200", "OK"], :body => xml)
30
25
  end
31
26
 
32
27
  it "can create an invoice" do
@@ -28,27 +28,11 @@ describe "Quickeebooks::Online::Service::ServiceBase" do
28
28
  }
29
29
  end
30
30
 
31
- it "can determine base url" do
32
- @service.determine_base_url
33
- @service.base_uri.should_not == nil
34
- @service.url_for_resource(Quickeebooks::Online::Model::Customer.resource_for_collection).should == "https://qbo.intuit.com/qbo36/resource/customers/v2/#{@realm_id}"
35
- end
36
-
37
31
  it "can determine login_name" do
32
+ xml = File.read(File.dirname(__FILE__) + "/../../../xml/online/user.xml")
33
+ user_url = "https://qbo.intuit.com/qbo1/rest/user/v2/#{@realm_id}"
34
+ FakeWeb.register_uri(:get, user_url, :status => ["200", "OK"], :body => xml)
38
35
  @service.login_name.should == 'foo@example.com'
39
36
  end
40
37
 
41
- it "throws exception when response XML is invalid when determining base url" do
42
- xml = File.read(File.dirname(__FILE__) + "/../../../xml/online/invalid_user.xml")
43
- user_url = Quickeebooks::Online::Service::ServiceBase::QB_BASE_URI + "/" + @realm_id
44
- FakeWeb.register_uri(:get, user_url, :status => ["200", "OK"], :body => xml)
45
- @service = Quickeebooks::Online::Service::ServiceBase.new
46
- @service.access_token = @oauth
47
- @service.instance_eval {
48
- @realm_id = "9991111222"
49
- }
50
- lambda { @service.determine_base_url }.should raise_error(IntuitRequestException)
51
- @service.base_uri.should == nil
52
- end
53
-
54
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quickeebooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-29 00:00:00.000000000 Z
12
+ date: 2013-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: roxml
@@ -179,6 +179,7 @@ extra_rdoc_files: []
179
179
  files:
180
180
  - Gemfile
181
181
  - Gemfile.lock
182
+ - HISTORY.md
182
183
  - lib/quickeebooks/online/model/account.rb
183
184
  - lib/quickeebooks/online/model/account_detail_type.rb
184
185
  - lib/quickeebooks/online/model/account_reference.rb