zoro 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
+ *.rbc
3
+ *.swp
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ .rvmrc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zoro.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Trevor Redfern
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,44 @@
1
+ # Zoro [![Build Status](https://secure.travis-ci.org/PayTrace/zoro.png)](http://travis-ci.org/PayTrace/zoro)
2
+
3
+ A gem for integrating with Zoho.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'zoro'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install zoro
18
+
19
+ ## Usage
20
+
21
+ First we need an authentication token setup for requests:
22
+
23
+ Zoro.auth_token = "SomeAuthToken"
24
+
25
+ You can customize Faraday behavior for logging or other things by replacing the Zoro connection. I'll probably change this down stream to allow more configurable.
26
+
27
+ Zoro.connection = Faraday::Connection.new |conn| do
28
+ conn.request :url_encoded
29
+ end
30
+
31
+ Current this is still very much a work in development, but for generating leads the following works:
32
+
33
+ lead = Zoro::Lead.new
34
+ lead.add_field "First Name", "Foo"
35
+ lead.add_field "Last Name", "Bar"
36
+ lead.save!
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ lib_dir = File.expand_path('lib')
5
+ test_dir = File.expand_path('test')
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ t.verbose = true
10
+ end
11
+ task "default" => ["test"]
12
+
@@ -0,0 +1,15 @@
1
+ require 'zoro'
2
+
3
+ Zoro.auth_token = 'some-valid-auth-token'
4
+ Zoro.http_connection = Faraday::Connection.new do |conn|
5
+ conn.request :url_encoded
6
+ conn.response :logger #Log Faraday to STDOUT for easier testing
7
+ conn.adapter Faraday.default_adapter
8
+ end
9
+
10
+ lead = Zoro::Lead.new
11
+ lead.add_field "First Name", "Test"
12
+ lead.add_field "Last Name", "trevor trevor"
13
+ lead.add_field "Email", "trevor@paytrace.com"
14
+ response = lead.save!
15
+ puts response.body
data/lib/zoro/api.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'faraday'
2
+
3
+ module Zoro
4
+ class Api
5
+ def format_url(mod, method)
6
+ "https://crm.zoho.com/crm/private/xml/#{mod}/#{method}"
7
+ end
8
+
9
+ def insert_records(record)
10
+ url = format_url(record.zoho_module, "insertRecords")
11
+ xml = record.to_xml
12
+ Zoro.http_connection.get(url, :xmlData => xml, :newformat => 1, :authtoken => Zoro.auth_token, :scope => 'crmapi')
13
+ end
14
+ end
15
+ end
data/lib/zoro/lead.rb ADDED
@@ -0,0 +1,37 @@
1
+ module Zoro
2
+ class Lead
3
+ ZOHO_MODULE = "Leads"
4
+ attr_accessor :fields, :api
5
+
6
+ def initialize(data = {})
7
+ @fields = {}.merge(data)
8
+ end
9
+
10
+ def save!
11
+ api.insert_records(self)
12
+ end
13
+
14
+ def api
15
+ @api ||= Zoro::Api.new
16
+ end
17
+
18
+ def add_field(field_name, value)
19
+ @fields[field_name] = value
20
+ end
21
+
22
+ def zoho_module
23
+ ZOHO_MODULE
24
+ end
25
+
26
+ def to_xml
27
+ xml_map = Hash.new
28
+ xml_map['row'] = {
29
+ 'no' => '1',
30
+ 'FL' => @fields.map do |k, v|
31
+ { 'val' => k, 'content' => v}
32
+ end
33
+ }
34
+ XmlSimple.xml_out(xml_map, :RootName => ZOHO_MODULE)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Zoro
2
+ VERSION = "0.0.1"
3
+ end
data/lib/zoro.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "zoro/version"
2
+ require 'zoro/api'
3
+ require 'zoro/lead'
4
+ require 'faraday'
5
+ require 'xmlsimple'
6
+
7
+ module Zoro
8
+ extend self
9
+ attr_accessor :auth_token, :http_connection
10
+
11
+ def http_connection
12
+ @http_connection ||= Faraday::Connection.new
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ require 'minitest/pride'
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
4
+ require 'mocha'
5
+ require 'zoro'
6
+
7
+
8
+ def stub_http
9
+ http_stubs = Faraday::Adapter::Test::Stubs.new do |stub|
10
+ end
11
+
12
+ Zoro.http_connection = Faraday::Connection.new do |builder|
13
+ builder.adapter :test, http_stubs
14
+ end
15
+ http_stubs
16
+ end
@@ -0,0 +1,23 @@
1
+ require './test/test_helper'
2
+ require 'zoro/api'
3
+
4
+ describe Zoro::Api do
5
+ it "can format the URL to insert lead records" do
6
+ Zoro.auth_token = "1234"
7
+ api = Zoro::Api.new
8
+ url = api.format_url("Leads", "insertRecords")
9
+ url.must_equal "https://crm.zoho.com/crm/private/xml/Leads/insertRecords"
10
+ end
11
+
12
+ it "can insert records into the zoro CRM" do
13
+ #Stub HTTP
14
+ Zoro.auth_token = "1234"
15
+ stubs = stub_http
16
+ stubs.get("/crm/private/xml/Leads/insertRecords") {[200, {}, 'foo']}
17
+
18
+ record = stub(:zoho_module => "Leads", :to_xml => '<somexml>foo</somexml>')
19
+ api = Zoro::Api.new
20
+ api.insert_records(record)
21
+ stubs.verify_stubbed_calls
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ require './test/test_helper'
2
+ require 'zoro/api'
3
+ require 'zoro/lead'
4
+
5
+
6
+ describe Zoro::Lead do
7
+ it "can create new leads" do
8
+ lead = Zoro::Lead.new
9
+ api = stub
10
+ api.expects(:insert_records).with(lead)
11
+ lead.api = api
12
+ lead.save!
13
+ end
14
+
15
+ it "defines it's module as Lead" do
16
+ Zoro::Lead::ZOHO_MODULE.must_equal "Leads"
17
+ end
18
+
19
+ it "can serialize itself to xml" do
20
+ lead = Zoro::Lead.new
21
+ lead.add_field "First Name", "foo"
22
+ lead.add_field "Last Name", "bar"
23
+ lead.to_xml.must_equal %q{<Leads>
24
+ <row no="1">
25
+ <FL val="First Name">foo</FL>
26
+ <FL val="Last Name">bar</FL>
27
+ </row>
28
+ </Leads>
29
+ }
30
+ end
31
+
32
+ it "can be constructed with fields" do
33
+ lead = Zoro::Lead.new({"First Name" => "Foo", "Last Name" => "Bar"})
34
+ lead.fields["First Name"].must_equal "Foo"
35
+ lead.fields["Last Name"].must_equal "Bar"
36
+ end
37
+ end
data/zoro.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zoro/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "zoro"
8
+ gem.version = Zoro::VERSION
9
+ gem.authors = ["Trevor Redfern"]
10
+ gem.email = ["trevor@paytrace.com"]
11
+ gem.description = %q{Simple integration library into Zoho CRM. Will be enhanced to provide two way integration with library over time.}
12
+ gem.summary = %q{Ruby gem for integration with Zoho CRM}
13
+ gem.homepage = "https://github.com/PayTrace/zoro"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency('rake')
21
+ gem.add_development_dependency('mocha')
22
+ gem.add_dependency('faraday')
23
+ gem.add_dependency('xml-simple')
24
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zoro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Trevor Redfern
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mocha
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
+ - !ruby/object:Gem::Dependency
47
+ name: faraday
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: xml-simple
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Simple integration library into Zoho CRM. Will be enhanced to provide
79
+ two way integration with library over time.
80
+ email:
81
+ - trevor@paytrace.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - examples/add_lead.rb
92
+ - lib/zoro.rb
93
+ - lib/zoro/api.rb
94
+ - lib/zoro/lead.rb
95
+ - lib/zoro/version.rb
96
+ - test/test_helper.rb
97
+ - test/zoro/api_test.rb
98
+ - test/zoro/lead_test.rb
99
+ - zoro.gemspec
100
+ homepage: https://github.com/PayTrace/zoro
101
+ licenses: []
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 1.8.24
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Ruby gem for integration with Zoho CRM
124
+ test_files:
125
+ - test/test_helper.rb
126
+ - test/zoro/api_test.rb
127
+ - test/zoro/lead_test.rb