infusionsoft-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in infusionsoft-api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 David Lumley
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Infusionsoft::Api
2
+
3
+ [Infusionsoft Api](https://github.com/davidlumley/infusionsoft-api) is an interface for accessing [Infusionsoft's](http://help.infusionsoft.com/developers/api-basics) API.
4
+
5
+ It's based on the [MYOB Api](https://github.com/davidlumley/myob-api) gem.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'infusionsoft-api'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install infusionsoft-api
20
+
21
+ ## Usage
22
+
23
+ ### API Client Setup
24
+
25
+ Create an api_client:
26
+
27
+ api_client = Infusionsoft::Api::Client.new({
28
+ :api_key => USERS_API_KEY,
29
+ :app_name => USERS_APP_NAME,
30
+ })
31
+
32
+ The `:api_key` can be found in Infusionsoft under Admin -> Settings -> Application Setttings (Application). The `:app_name` is the subdomain of `app_name.infusionsoft.com`('app_name').
33
+
34
+ ### API Methods
35
+
36
+ #### Contacts
37
+
38
+ Return a list of all contacts
39
+
40
+ api_client.contact.all
41
+
42
+ You can also pass a query hash
43
+
44
+ api_client.contact.all({
45
+ :FirstName => 'David',
46
+ })
47
+
48
+ #### Contact Groups
49
+
50
+ Return a list of all contact groups (i.e. contacts with a tag or group)
51
+ api_client.contact_group.all
52
+
53
+ You can also pass a hash query
54
+
55
+ api_client.contact_group.all({
56
+ :ContactGroup => 'New Customer',
57
+ })
58
+
59
+ ## Todo
60
+
61
+ * Expand API methods
62
+ * Refactor client factory architecture
63
+ * Tests
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'infusionsoft/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "infusionsoft-api"
8
+ spec.version = Infusionsoft::Api::VERSION
9
+ spec.authors = ["David Lumley"]
10
+ spec.email = ["david@davidlumley.com.au"]
11
+ spec.description = %q{Infusionsoft API}
12
+ spec.summary = %q{Infusionsoft API}
13
+ spec.homepage = "https://github.com/davidlumley/infusionsoft-api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,9 @@
1
+ require "infusionsoft/api/version"
2
+
3
+ require 'infusionsoft/api/helpers'
4
+
5
+ require 'infusionsoft/api/models/base'
6
+ require 'infusionsoft/api/models/contact'
7
+ require 'infusionsoft/api/models/contact_group'
8
+
9
+ require 'infusionsoft/api/client'
@@ -0,0 +1,24 @@
1
+ require 'xmlrpc/client'
2
+
3
+ module Infusionsoft
4
+ module Api
5
+ class Client
6
+ include Infusionsoft::Api::Helpers
7
+
8
+ attr_reader :api_key, :app_name
9
+
10
+ def initialize(options)
11
+ model :Contact
12
+ model :ContactGroup
13
+
14
+ @api_key = options[:api_key]
15
+ @app_name = options[:app_name]
16
+ end
17
+
18
+ def connection
19
+ @client ||= XMLRPC::Client.new2("https://#{@app_name}.infusionsoft.com:443/api/xmlrpc")
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ class String
2
+ def underscore
3
+ self.gsub(/::/, '/').
4
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
6
+ tr("-", "_").
7
+ downcase
8
+ end
9
+ end
10
+
11
+ module Infusionsoft
12
+ module Api
13
+ module Helpers
14
+ def model(model_name)
15
+ variable_name = "@#{model_name.to_s.underscore}_model".to_sym
16
+ unless instance_variable_defined?(variable_name)
17
+ instance_variable_set(variable_name, Infusionsoft::Api::Model.const_get("#{model_name}".to_sym).new(self, model_name.to_s))
18
+ self.define_singleton_method("#{model_name.to_s.underscore}".to_sym) do
19
+ instance_variable_get(variable_name)
20
+ end
21
+ end
22
+ instance_variable_get(variable_name)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ module Infusionsoft
2
+ module Api
3
+ module Model
4
+ class Base
5
+
6
+ def initialize(client, model_name)
7
+ @client = client
8
+ @model_name = model_name || 'Base'
9
+ end
10
+
11
+ def all(query = {}, page_number = 0)
12
+ results = @client.connection.call('DataService.query', @client.api_key, self.table_name, 1000, page_number, query, self.fields)
13
+ results.length > 0 ? results + self.all(query, page_number + 1) : results
14
+ end
15
+
16
+ def table_name
17
+ @model_name
18
+ end
19
+
20
+ def fields
21
+ []
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ module Infusionsoft
2
+ module Api
3
+ module Model
4
+ class Contact < Infusionsoft::Api::Model::Base
5
+
6
+ def fields
7
+ [:FirstName, :LastName, :Company, :Email]
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Infusionsoft
2
+ module Api
3
+ module Model
4
+ class ContactGroup < Infusionsoft::Api::Model::Base
5
+
6
+ def table_name
7
+ 'ContactGroupAssign'
8
+ end
9
+
10
+ def fields
11
+ [:ContactGroup, :'Contact.FirstName', :'Contact.LastName', :'Contact.Company', :'Contact.Email']
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Infusionsoft
2
+ module Api
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infusionsoft-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Lumley
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Infusionsoft API
47
+ email:
48
+ - david@davidlumley.com.au
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - infusionsoft-api.gemspec
59
+ - lib/infusionsoft/api.rb
60
+ - lib/infusionsoft/api/client.rb
61
+ - lib/infusionsoft/api/helpers.rb
62
+ - lib/infusionsoft/api/models/base.rb
63
+ - lib/infusionsoft/api/models/contact.rb
64
+ - lib/infusionsoft/api/models/contact_group.rb
65
+ - lib/infusionsoft/api/version.rb
66
+ homepage: https://github.com/davidlumley/infusionsoft-api
67
+ licenses:
68
+ - MIT
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ segments:
80
+ - 0
81
+ hash: -3359927660206814433
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ segments:
89
+ - 0
90
+ hash: -3359927660206814433
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.23
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Infusionsoft API
97
+ test_files: []