saasu 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,9 +19,11 @@ To fetch all invoices
19
19
 
20
20
  invoices = Saasu::Invoice.all
21
21
 
22
+ By default all sales purchases are retrieved as this field is required.
23
+
22
24
  You can pass in any conditions as a hash. The keys should be in snake case.
23
25
 
24
- invoices = Saasu::Invoice.all(:transaction_type => "s", :paid_status => "Unpaid")
26
+ invoices = Saasu::Invoice.all(:transaction_type => "p", :paid_status => "Unpaid")
25
27
 
26
28
  For a complete list of supported options see the [Saasu API Reference](http://help.saasu.com/api/http-get/)
27
29
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/saasu.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__))
2
2
 
3
3
  require "rubygems"
4
+ require "date"
4
5
  require "uri"
5
6
  require "net/https"
6
7
  require "nokogiri"
data/lib/saasu/base.rb CHANGED
@@ -6,6 +6,7 @@ module Saasu
6
6
 
7
7
  def initialize(xml)
8
8
  klass = self.class.name.split("::")[1].downcase
9
+
9
10
  xml.children.each do |child|
10
11
  if !child.text?
11
12
  child.attributes.each do |attr|
@@ -70,8 +71,13 @@ module Saasu
70
71
  # Generally the class name will be suitable and options will not need to be provided
71
72
  # @param [Hash] options to override the default settings
72
73
  #
73
- def defaults(options = {})
74
- default_options.merge!(options)
74
+ def defaults(options = nil)
75
+ @defaults ||= default_options
76
+ if options
77
+ @defaults = default_options.merge!(options)
78
+ else
79
+ @defaults
80
+ end
75
81
  end
76
82
 
77
83
  protected
@@ -79,10 +85,11 @@ module Saasu
79
85
  # Default options for the class
80
86
  #
81
87
  def default_options
82
- defaults = {}
83
- defaults[:resource_name] = name.split("::").last.downcase
84
- defaults[:collection_name] = name.split("::").last.downcase + "ListItem"
85
- defaults
88
+ options = {}
89
+ options[:query_options] ||= {}
90
+ options[:resource_name] = name.split("::").last.downcase
91
+ options[:collection_name] = name.split("::").last.downcase + "ListItem"
92
+ options
86
93
  end
87
94
 
88
95
  # Defines the fields for a resource and any transformations
@@ -95,7 +102,7 @@ module Saasu
95
102
  end
96
103
 
97
104
  def define_accessor(field, type)
98
- m = field.sub(/#{defaults[:resource_name]}_/, "")
105
+ m = field.sub(/^#{defaults[:resource_name]}_/, "")
99
106
  case type
100
107
  when :decimal
101
108
  class_eval <<-END
@@ -148,17 +155,16 @@ module Saasu
148
155
  #
149
156
  def get(options = {}, all = true)
150
157
  uri = URI.parse(request_path(options, all))
151
- puts request_path(options, all)
152
158
  http = Net::HTTP.new(uri.host, uri.port)
153
159
  http.use_ssl = true
154
160
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
155
161
  response = http.request(Net::HTTP::Get.new(uri.request_uri))
156
- puts response.body
157
162
  (options[:format] && options[:format] == "pdf") ? response.body : response.body
158
163
  end
159
164
 
160
165
  def query_string(options = {})
161
- options = { :wsaccesskey => api_key, :fileuid => file_uid }.merge!(options)
166
+ options = defaults[:query_options].merge(options)
167
+ options = { :wsaccesskey => api_key, :fileuid => file_uid }.merge(options)
162
168
  options.map { |k,v| "#{k.to_s.gsub(/_/, "")}=#{v}"}.join("&")
163
169
  end
164
170
 
data/lib/saasu/invoice.rb CHANGED
@@ -37,6 +37,7 @@ module Saasu
37
37
  "totalAmountPaid" => :decimal,
38
38
  "invoiceItems" => :array
39
39
 
40
+ defaults :query_options => { :transaction_type => "s" }
40
41
  end
41
42
 
42
43
  end
data/saasu.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{saasu}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kieran Johnson"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saasu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kieran Johnson