shelby-arena-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 931e155b3330e3297457065c53aaea47172a4875
4
+ data.tar.gz: a9dfb77ccee9f40d6dc9579988f69f20d7927fbe
5
+ SHA512:
6
+ metadata.gz: bd8f6dc7dc5c054693b48b16a627466222bf571df86b1199d90449bdb5b6c96b9b4986c0fafc893650f079a0c2fcd9a33225b3ebbccde24d6fb457037e82a37e
7
+ data.tar.gz: c0948853eed75f02d0ed68da5ad52f5c4da3769db3a418e6e14f8302208ddccef5d05621638e346dfd570485047161feb91ba19b50f69b0cd4ab351bc1896e19
@@ -0,0 +1,10 @@
1
+ shelby-arena-api-*.gem
2
+ .DS_Store
3
+ storage/*
4
+ doc/*
5
+ bin/
6
+ .bundle/
7
+ .rbenv-version
8
+ index.rb
9
+ .idea/*
10
+ coverage
@@ -0,0 +1 @@
1
+ shelby-arena-api
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'typhoeus', '0.6.6'
4
+ gem 'json'
5
+ gem 'xml-simple'
6
+ gem 'virtus', '1.0.2'
7
+
8
+ group :development, :test do
9
+ gem 'rspec'
10
+ gem 'debugger'
11
+ gem 'factory_girl'
12
+
13
+ gem 'vcr'
14
+ gem 'webmock', '1.9' # Currently does not work with Typhoeus 0.4.2 - THIS SUCKS!
15
+ end
@@ -0,0 +1,79 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.4)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.5)
11
+ atomic (1.1.16)
12
+ axiom-types (0.1.0)
13
+ descendants_tracker (~> 0.0.3)
14
+ ice_nine (~> 0.11.0)
15
+ thread_safe (~> 0.1.3)
16
+ coercible (1.0.0)
17
+ descendants_tracker (~> 0.0.1)
18
+ columnize (0.3.6)
19
+ crack (0.4.2)
20
+ safe_yaml (~> 1.0.0)
21
+ debugger (1.6.6)
22
+ columnize (>= 0.3.1)
23
+ debugger-linecache (~> 1.2.0)
24
+ debugger-ruby_core_source (~> 1.3.2)
25
+ debugger-linecache (1.2.0)
26
+ debugger-ruby_core_source (1.3.2)
27
+ descendants_tracker (0.0.3)
28
+ diff-lcs (1.2.5)
29
+ equalizer (0.0.9)
30
+ ethon (0.6.3)
31
+ ffi (>= 1.3.0)
32
+ mime-types (~> 1.18)
33
+ factory_girl (4.4.0)
34
+ activesupport (>= 3.0.0)
35
+ ffi (1.9.3)
36
+ i18n (0.6.9)
37
+ ice_nine (0.11.0)
38
+ json (1.8.1)
39
+ mime-types (1.25.1)
40
+ minitest (4.7.5)
41
+ multi_json (1.9.0)
42
+ rspec (2.14.1)
43
+ rspec-core (~> 2.14.0)
44
+ rspec-expectations (~> 2.14.0)
45
+ rspec-mocks (~> 2.14.0)
46
+ rspec-core (2.14.8)
47
+ rspec-expectations (2.14.5)
48
+ diff-lcs (>= 1.1.3, < 2.0)
49
+ rspec-mocks (2.14.6)
50
+ safe_yaml (1.0.1)
51
+ thread_safe (0.1.3)
52
+ atomic
53
+ typhoeus (0.6.6)
54
+ ethon (~> 0.6.1)
55
+ tzinfo (0.3.39)
56
+ vcr (2.8.0)
57
+ virtus (1.0.2)
58
+ axiom-types (~> 0.1)
59
+ coercible (~> 1.0)
60
+ descendants_tracker (~> 0.0.3)
61
+ equalizer (~> 0.0.9)
62
+ webmock (1.9.0)
63
+ addressable (>= 2.2.7)
64
+ crack (>= 0.1.7)
65
+ xml-simple (1.1.3)
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ debugger
72
+ factory_girl
73
+ json
74
+ rspec
75
+ typhoeus (= 0.6.6)
76
+ vcr
77
+ virtus (= 1.0.2)
78
+ webmock (= 1.9)
79
+ xml-simple
@@ -0,0 +1,42 @@
1
+ = Shelby Arena API
2
+
3
+ This Ruby project is an API wrapper for the Shelby Arena API
4
+
5
+
6
+ == Install / Setup
7
+
8
+ Installing the gem
9
+
10
+ gem install shelby-arena-api
11
+
12
+
13
+ To add it to your Gemfile
14
+
15
+ gem 'shelby-arena-api', require: 'shelby_arena'
16
+
17
+
18
+ == Example usage
19
+
20
+ Checkout the examples folder.
21
+
22
+
23
+ == Additional resources
24
+
25
+ Checkout the docs folder for the PDF.
26
+
27
+
28
+ == License
29
+
30
+ This project is released under the MIT license (see LICENSE).
31
+
32
+ This project is maintained by Wes Hays (https://github.com/weshays).
33
+
34
+
35
+ == Contributors
36
+
37
+ Wanna help? It could be you...
38
+
39
+
40
+ == Want to Contribute?
41
+
42
+ If you would like to get involved in this project, then please fork the project. Make changes, add features, write some tests, and then send a pull request.
@@ -0,0 +1,32 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+
4
+ desc 'Default: run specs.'
5
+ task :default => :spec
6
+ task :test => :spec
7
+
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new do |t|
10
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
11
+ # Put spec opts in a file named .rspec in root
12
+ end
13
+
14
+
15
+ desc "Generate code coverage"
16
+ RSpec::Core::RakeTask.new(:coverage) do |t|
17
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
18
+ t.rcov = true
19
+ t.rcov_opts = ['--exclude', 'spec']
20
+ end
21
+
22
+
23
+
24
+ namespace :docs do
25
+
26
+ desc 'Build the docs for the FellowshipOne API.'
27
+ task :build do
28
+ system('rm -rf doc')
29
+ system('yardoc --no-private --protected lib/**/*.rb')
30
+ end
31
+
32
+ end
Binary file
@@ -0,0 +1,28 @@
1
+ module ShelbyArena
2
+
3
+ # This is a helper class for the person object so the data coming
4
+ # through via Virtus is a hash that has been converted to an array.
5
+ class Address < ApiObject
6
+ attribute :address_id, Integer
7
+ attribute :city, String
8
+ attribute :country, String
9
+ attribute :latitude, String
10
+ attribute :longitude, String
11
+ attribute :postal_code, String
12
+ attribute :primary, Boolean
13
+ attribute :state, String
14
+ attribute :street_line_1, String
15
+
16
+
17
+ # Constructor.
18
+ #
19
+ # @param data A hash of data
20
+ def initialize(data)
21
+ # data[0] is 'Address'
22
+ # data[1] is a Hash of address info to match the attributes above.
23
+ initialize_from_json_object(data[1])
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,32 @@
1
+ require 'virtus'
2
+
3
+ module ShelbyArena
4
+
5
+ # This class is the base class for all ShelbyArena objects and is meant to be inherited.
6
+ class ApiObject
7
+ include Virtus.model
8
+
9
+ attr_reader :error_messages, :marked_for_destruction
10
+
11
+ # Initializes the current object from the JSON data that was loaded into the Hash
12
+ #
13
+ # @param object_attributes A Hash of values to load into the current object.
14
+ def initialize_from_json_object(object_attributes)
15
+ if object_attributes.is_a?( Hash )
16
+ object_attributes.each do |key, value|
17
+ method_to_call = "#{ShelbyArena::attr_underscore(key)}="
18
+
19
+ if respond_to?(method_to_call)
20
+ self.send(method_to_call, value)
21
+ else
22
+ # debugger
23
+ # asdf=234
24
+ # puts "Missing :=> ".red + method_to_call.to_s # Show the missing methods
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,42 @@
1
+ module ShelbyArena
2
+
3
+ class Contribution < ApiObject
4
+ attribute :contribution_id, Integer
5
+ attribute :transaction_number, Integer
6
+ attribute :currency_amount, Float
7
+ attribute :contribution_date, Date
8
+ attribute :contribution_funds, Hash
9
+ attribute :currency_type_id, Integer
10
+ attribute :currency_type_value, String
11
+ attribute :person_id, Integer
12
+ attribute :person_information, Hash
13
+ attribute :person_link, String
14
+ attribute :batch_id, Integer
15
+ attribute :batch_link, String
16
+ attribute :refund_contribution_id, Integer
17
+
18
+
19
+ # Load the contribution by the specified ID.
20
+ #
21
+ # @param contribution_id The ID of the contribution to load.
22
+ #
23
+ # Returns a new Contribution object.
24
+ def self.load_by_id(contribution_id)
25
+ reader = ContributionReader.new(contribution_id)
26
+ self.new(reader)
27
+ end
28
+
29
+ # Constructor.
30
+ #
31
+ # @param reader (optional) The object that has the data. This can be a ContributionReader or Hash object.
32
+ def initialize(reader = nil)
33
+ if reader.is_a?(ContributionReader)
34
+ initialize_from_json_object(reader.load_data['Contribution'])
35
+ elsif reader.is_a?(Hash)
36
+ initialize_from_json_object(reader)
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,49 @@
1
+ module ShelbyArena
2
+
3
+ class ContributionList
4
+
5
+ include Enumerable
6
+
7
+ # attr_reader :count, :page_number, :total_records, :additional_pages
8
+
9
+
10
+ # Constructor.
11
+ #
12
+ # @param options A hash of options for loading the list.
13
+ #
14
+ # Options:
15
+ # :reader - (optional) The Reader to use to load the data.
16
+ def initialize(options = {})
17
+ reader = options[:reader] || ShelbyArena::ContributionListReader.new(options)
18
+ @json_data = reader.load_data['ContributionListResult']['Contributions']['Contribution']
19
+ end
20
+
21
+ # Get the specified contribution.
22
+ #
23
+ # @param index The index of the contribution to get.
24
+ #
25
+ # @return Contribution
26
+ def [](index)
27
+ Contribution.new( @json_data[index] ) unless @json_data[index].nil?
28
+ end
29
+
30
+
31
+ # This method is needed for Enumerable.
32
+ def each &block
33
+ @json_data.each{ |contribution| yield( Contribution.new(contribution) )}
34
+ end
35
+
36
+ # Alias the count method
37
+ alias :size :count
38
+
39
+
40
+ # Checks if the list is empty.
41
+ #
42
+ # @return True on empty, false otherwise.
43
+ def empty?
44
+ self.count == 0 ? true : false
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/person.rb'
2
+
3
+ module ShelbyArena
4
+
5
+ class Family < ApiObject
6
+ attribute :family_id, Integer
7
+ attribute :family_name, String
8
+ attribute :family_members, Array
9
+
10
+ # Loads the family by the specified ID.
11
+ #
12
+ # @param family The ID of the family to load.
13
+ #
14
+ # Returns a new Family object.
15
+ def self.load_by_id(family_id)
16
+ reader = FamilyReader.new(family_id)
17
+ self.new(reader)
18
+ rescue
19
+ nil
20
+ end
21
+
22
+
23
+ # Constructor.
24
+ #
25
+ # @param reader (optional) The object that has the data. This can be a PersonReader or Hash object.
26
+ # @param options (optional) Options for including more information.
27
+ def initialize(reader = nil, options = {})
28
+ #@writer_object = FamilyWriter
29
+ if reader.is_a?(FamilyReader)
30
+ initialize_from_json_object(reader.load_data['Family'])
31
+ elsif reader.is_a?(Hash)
32
+ initialize_from_json_object(reader)
33
+ else # new empty
34
+ raise 'Not sure about this one yet'
35
+ # reader = FamilyReader.new
36
+ # initialize_from_json_object(reader.load_new['family'])
37
+ end
38
+
39
+ # The data loaded from family_members is useless. It is best to just reload all the family
40
+ # members as person objects so all attributes are set.
41
+ # fm[0] is 'Person'
42
+ # fm[1] is a Hash of person info to match some, not all, of the attributes above.
43
+ method_to_call = "#{ShelbyArena::attr_underscore('family_members')}="
44
+ self.send(method_to_call, self.family_members.collect { |fm| ShelbyArena::Person.load_by_id(fm[1]['PersonID']) })
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,37 @@
1
+ module ShelbyArena
2
+
3
+ class Fund < ApiObject
4
+ attribute :fund_id, Integer
5
+ attribute :fund_name, String
6
+ attribute :online_name, String
7
+ attribute :start_date, Date
8
+ attribute :end_date, Date
9
+ attribute :active, Boolean
10
+ attribute :can_pledge, Boolean
11
+ attribute :tax_deductible, Boolean
12
+
13
+
14
+ # Load the fund by the specified ID.
15
+ #
16
+ # @param fund_id The ID of the fund to load.
17
+ #
18
+ # Returns a new Fund object.
19
+ def self.load_by_id(fund_id)
20
+ reader = FundReader.new(fund_id)
21
+ self.new(reader)
22
+ end
23
+
24
+ # Constructor.
25
+ #
26
+ # @param reader (optional) The object that has the data. This can be a FundReader or Hash object.
27
+ def initialize(reader = nil)
28
+ if reader.is_a?(FundReader)
29
+ initialize_from_json_object(reader.load_data['Fund'])
30
+ elsif reader.is_a?(Hash)
31
+ initialize_from_json_object(reader)
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ end