biller_bot_resource 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ pkg/*
4
+ *.rbc
5
+ *.sassc
6
+ .sass-cache
7
+ capybara-*.html
8
+ .rspec
9
+ /.bundle
10
+ /vendor/bundle
11
+ /log/*
12
+ /tmp/*
13
+ /db/*.sqlite3
14
+ /public/system/*
15
+ /coverage/
16
+ /spec/tmp/*
17
+ **.orig
18
+ rerun.txt
19
+ pickle-email-*.html
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in biller_bot_resource.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ biller_bot_resource
2
+ ===================
3
+
4
+ Common resources for interacting with the BillerBot API
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "biller_bot_resource/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "biller_bot_resource"
7
+ s.version = BillerBotResource::VERSION
8
+ s.authors = ["Brad Seefeld"]
9
+ s.email = ["support@dispatchbot.com"]
10
+ s.homepage = "https://github.com/bradseefeld/biller_bot_resource"
11
+ s.summary = %q{Common resources for the BillerBot API}
12
+ s.description = %q{Provides a set of Ruby classes for interacting with the BillerBot API}
13
+
14
+ s.rubyforge_project = "biller_bot_resource"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,3 @@
1
+ class BillerBotResource::Account < BillerBotResource::Resource
2
+
3
+ end
@@ -0,0 +1,7 @@
1
+ class BillerBotResource::Configuration
2
+ attr_accessor :site, :logger, :api_key
3
+
4
+ def initialize
5
+ self.site = "https://billerbot.com"
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ class BillerBotResource::Invoice < BillerBotResource::Resource
2
+
3
+ class Status < BillerBotResource::Resource
4
+ def display_name
5
+ @attributes[:name].try(:capitalize)
6
+ end
7
+ end
8
+
9
+ def locations
10
+ @attributes[:locations] ||= []
11
+ @attributes[:locations]
12
+ end
13
+
14
+ def line_items
15
+ @attributes[:line_items] ||= []
16
+ @attributes[:line_items]
17
+ end
18
+
19
+ def save
20
+ @attributes[:line_items_attributes] = @attributes.delete :line_items
21
+ @attributes[:locations_attributes] = @attributes.delete :locations
22
+ super
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ class BillerBotResource::LineItem < BillerBotResource::Resource
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class BillerBotResource::Location < BillerBotResource::Resource
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class BillerBotResource::Product < BillerBotResource::Resource
2
+
3
+ end
@@ -0,0 +1,74 @@
1
+ class BillerBotResource::Resource < ActiveResource::Base
2
+
3
+ self.include_root_in_json = false
4
+ self.format = :json
5
+
6
+ ##
7
+ # Allow the resource to be configured via block style.
8
+ def self.configure
9
+ yield config
10
+
11
+ self.site = config.site
12
+ self.logger = config.logger if config.logger
13
+ end
14
+
15
+ def self.config
16
+ if defined?(@config)
17
+ @config
18
+ elsif superclass != ActiveResource::Base && superclass.respond_to?(:config) && !superclass.config.nil?
19
+ superclass.config
20
+ else
21
+ @config = BillerBotResource::Configuration.new
22
+ @config
23
+ end
24
+ end
25
+
26
+ ##
27
+ # Append the auth token to all of our queries. The easiest way to do this
28
+ # is to override the query string method and inject it.
29
+ def self.query_string(options)
30
+ options ||= {}
31
+ options[:auth_token] = config.api_key
32
+ super(options)
33
+ end
34
+
35
+ def self.instantiate_collection(collection, prefix_options = {})
36
+ return super if collection.is_a? Array
37
+ remote_collection = []
38
+ remote_collection.concat super(collection["results"], prefix_options)
39
+ # TODO: Add additional keys to the remote collection
40
+ remote_collection
41
+ end
42
+
43
+ def initialize(attributes = {}, persisted = false)
44
+ attributes = enrich_attributes(attributes)
45
+ super(attributes, persisted)
46
+ end
47
+
48
+ protected
49
+
50
+ ##
51
+ # Convert string values to more complex types such as Time.
52
+ #
53
+ # @return [Hash] The new attributes
54
+ def enrich_attributes(attributes)
55
+ attrs = {}
56
+ attributes.each do |key, value|
57
+ if time_field?(key, value)
58
+ begin
59
+ value = Time.parse(value)
60
+ rescue
61
+ # Ignore
62
+ end
63
+ end
64
+
65
+ attrs[key] = value
66
+ end
67
+
68
+ attrs
69
+ end
70
+
71
+ def time_field?(name, value)
72
+ name =~ /_at$/i && value && value.is_a?(String)
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module BillerBotResource
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,12 @@
1
+ require "biller_bot_resource/version"
2
+ require "biller_bot_resource/resource"
3
+ require "biller_bot_resource/configuration"
4
+ require "biller_bot_resource/account"
5
+ require "biller_bot_resource/location"
6
+ require "biller_bot_resource/line_item"
7
+ require "biller_bot_resource/invoice"
8
+ require "biller_bot_resource/product"
9
+
10
+ module BillerBotResource
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: biller_bot_resource
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Brad Seefeld
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2013-04-07 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Provides a set of Ruby classes for interacting with the BillerBot API
22
+ email:
23
+ - support@dispatchbot.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README.md
34
+ - Rakefile
35
+ - biller_bot_resource.gemspec
36
+ - lib/biller_bot_resource.rb
37
+ - lib/biller_bot_resource/account.rb
38
+ - lib/biller_bot_resource/configuration.rb
39
+ - lib/biller_bot_resource/invoice.rb
40
+ - lib/biller_bot_resource/line_item.rb
41
+ - lib/biller_bot_resource/location.rb
42
+ - lib/biller_bot_resource/product.rb
43
+ - lib/biller_bot_resource/resource.rb
44
+ - lib/biller_bot_resource/version.rb
45
+ has_rdoc: true
46
+ homepage: https://github.com/bradseefeld/biller_bot_resource
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project: biller_bot_resource
71
+ rubygems_version: 1.3.6
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Common resources for the BillerBot API
75
+ test_files: []
76
+