zoro 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fbc633abc04c8d95cb582644e7c87accbf70ee05
4
+ data.tar.gz: 7abaf44bfb898af8d11962b8f6e4426477def962
5
+ SHA512:
6
+ metadata.gz: db59357b062a91e5bdd81965b975bf48a7621e576ec7909c3d624f35c2ed7e2d928fb57898ebe9d1d81f3ce3209df05feb807e35aca7984d225ed254b5bee774
7
+ data.tar.gz: 119ccb0521da7880cb7ed6012170d1c0bf6c0dbc94e4aa933e0624b801ab9e8b85c92a3e077b9b0654731ab562ff6d2dc2080af38cdab0c18959ce247bc37c65
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ zoro
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Zoro [![Build Status](https://secure.travis-ci.org/PayTrace/zoro.png)](http://travis-ci.org/PayTrace/zoro)
1
+ # Zoro [Build Status](https://www.codeship.io/projects/477586c0-0cdf-0131-c895-42ce94ecf3ea/status)
2
2
 
3
3
  A gem for integrating with Zoho.
4
4
 
data/lib/zoro.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require "zoro/version"
2
2
  require 'zoro/api'
3
+ require 'zoro/record'
3
4
  require 'zoro/lead'
5
+ require 'zoro/account'
4
6
  require 'faraday'
5
7
  require 'xmlsimple'
6
8
 
@@ -0,0 +1,5 @@
1
+ module Zoro
2
+ class Account < Record
3
+ end
4
+ end
5
+
@@ -0,0 +1,13 @@
1
+ module Zoro
2
+ module FieldName
3
+ def self.make_field(name)
4
+ clean_up = name.gsub(/_/, ' ')
5
+ clean_up = clean_up.gsub(/=/, '')
6
+
7
+ words = clean_up.split
8
+ words.map do |w|
9
+ w.capitalize
10
+ end.join(" ")
11
+ end
12
+ end
13
+ end
data/lib/zoro/lead.rb CHANGED
@@ -1,37 +1,12 @@
1
1
  module Zoro
2
- class Lead
3
- ZOHO_MODULE = "Leads"
4
- attr_accessor :fields, :api
5
-
2
+ class Lead < Record
6
3
  def initialize(data = {})
7
4
  @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
5
+ @zoho_module = "Leads"
16
6
  end
17
7
 
18
8
  def add_field(field_name, value)
19
9
  @fields[field_name] = value
20
10
  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
11
  end
37
12
  end
@@ -0,0 +1,54 @@
1
+ module Zoro
2
+ class Record
3
+ attr_reader :zoho_module, :fields
4
+
5
+ def initialize(zoho_module= self.class.name)
6
+ @zoho_module = zoho_module
7
+ @fields = {}
8
+ end
9
+
10
+ def api=(api)
11
+ @api = api
12
+ end
13
+
14
+ def api
15
+ @api ||= Zoro::Api.new
16
+ end
17
+
18
+ def save!
19
+ api.insert_records(self)
20
+ end
21
+
22
+ def to_xml
23
+ xml_map = Hash.new
24
+ xml_map['row'] = {
25
+ 'no' => '1',
26
+ 'FL' => @fields.map do |k, v|
27
+ { 'val' => k, 'content' => v}
28
+ end
29
+ }
30
+ XmlSimple.xml_out(xml_map, :RootName => @zoho_module)
31
+ end
32
+
33
+ def method_missing(name, *args, &block)
34
+ property_name = Zoro::FieldName.make_field(name.to_s)
35
+
36
+ assignment = name.to_s.match(/=/)
37
+ if assignment
38
+ set_field property_name, args[0]
39
+ else
40
+ get_field property_name
41
+ end
42
+ end
43
+
44
+ protected
45
+ def set_field(name, value)
46
+ @fields[name] = value
47
+ end
48
+
49
+ def get_field(name)
50
+ @fields[name]
51
+ end
52
+
53
+ end
54
+ end
data/lib/zoro/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Zoro
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require './test/test_helper.rb'
2
+ require 'zoro/api'
3
+ require 'zoro/account'
4
+
5
+ describe Zoro::Account do
6
+ it "you have can set the primary fields and it will save them out to xml" do
7
+ account = Zoro::Account.new
8
+ account.account_name = "Target"
9
+ account.account_type = "Customer"
10
+ account.parent_account = "Chimney Sweeper"
11
+ account.billing_street = "123 Main St"
12
+ account.billing_city = "St. Louis"
13
+ account.billing_state = "MO"
14
+ account.billing_zip = "37238"
15
+
16
+ #sets up the zoho record
17
+ account.fields["Account Name"].must_equal "Target"
18
+ account.fields["Account Type"].must_equal "Customer"
19
+ account.fields["Parent Account"].must_equal "Chimney Sweeper"
20
+ account.fields["Billing Street"].must_equal "123 Main St"
21
+ account.fields["Billing City"].must_equal "St. Louis"
22
+ account.fields["Billing State"].must_equal "MO"
23
+ account.fields["Billing Zip"].must_equal "37238"
24
+ end
25
+ end
26
+
27
+
@@ -0,0 +1,9 @@
1
+ require './test/test_helper'
2
+ require 'zoro/field_name'
3
+
4
+ describe Zoro::FieldName do
5
+ it "generates a good field name from a symbol" do
6
+ Zoro::FieldName.make_field("foo_bar_one").must_equal "Foo Bar One"
7
+ Zoro::FieldName.make_field("foo_bar_two=").must_equal "Foo Bar Two"
8
+ end
9
+ end
@@ -13,7 +13,8 @@ describe Zoro::Lead do
13
13
  end
14
14
 
15
15
  it "defines it's module as Lead" do
16
- Zoro::Lead::ZOHO_MODULE.must_equal "Leads"
16
+ l = Zoro::Lead.new
17
+ l.zoho_module.must_equal "Leads"
17
18
  end
18
19
 
19
20
  it "can serialize itself to xml" do
@@ -0,0 +1,39 @@
1
+ require './test/test_helper.rb'
2
+ require 'zoro/record.rb'
3
+
4
+ class TestRecord < Zoro::Record
5
+ end
6
+
7
+ describe Zoro::Record do
8
+ it "serializes itself out to zoho xml" do
9
+ r = TestRecord.new
10
+ r.fields["Foo"] = "a foo"
11
+ r.fields["Bar"] = "a bar"
12
+ xml = r.to_xml
13
+ xml.must_equal %q{<TestRecord>
14
+ <row no="1">
15
+ <FL val="Foo">a foo</FL>
16
+ <FL val="Bar">a bar</FL>
17
+ </row>
18
+ </TestRecord>
19
+ }
20
+ end
21
+
22
+ it "relays itself to zoho api" do
23
+ r = TestRecord.new
24
+ api = stub
25
+ api.expects(:insert_records).with(r)
26
+ r.api = api
27
+ r.save!
28
+ end
29
+
30
+ it "uses the name of anything not defined as a field in the record" do
31
+ r = TestRecord.new
32
+ r.property_one = "foo"
33
+ r.another_name = "value"
34
+ r.fields["Property One"].must_equal "foo"
35
+ r.fields["Another Name"].must_equal "value"
36
+ r.property_one.must_equal "foo"
37
+ r.another_name.must_equal "value"
38
+ end
39
+ end
metadata CHANGED
@@ -1,78 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zoro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Trevor Redfern
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-14 00:00:00.000000000 Z
11
+ date: 2013-10-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: mocha
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: faraday
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: xml-simple
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  description: Simple integration library into Zoho CRM. Will be enhanced to provide
@@ -84,44 +75,54 @@ extensions: []
84
75
  extra_rdoc_files: []
85
76
  files:
86
77
  - .gitignore
78
+ - .ruby-gemset
79
+ - .ruby-version
87
80
  - Gemfile
88
81
  - LICENSE.txt
89
82
  - README.md
90
83
  - Rakefile
91
84
  - examples/add_lead.rb
92
85
  - lib/zoro.rb
86
+ - lib/zoro/account.rb
93
87
  - lib/zoro/api.rb
88
+ - lib/zoro/field_name.rb
94
89
  - lib/zoro/lead.rb
90
+ - lib/zoro/record.rb
95
91
  - lib/zoro/version.rb
96
92
  - test/test_helper.rb
93
+ - test/zoro/account_test.rb
97
94
  - test/zoro/api_test.rb
95
+ - test/zoro/field_name_test.rb
98
96
  - test/zoro/lead_test.rb
97
+ - test/zoro/record_test.rb
99
98
  - zoro.gemspec
100
99
  homepage: https://github.com/PayTrace/zoro
101
100
  licenses: []
101
+ metadata: {}
102
102
  post_install_message:
103
103
  rdoc_options: []
104
104
  require_paths:
105
105
  - lib
106
106
  required_ruby_version: !ruby/object:Gem::Requirement
107
- none: false
108
107
  requirements:
109
- - - ! '>='
108
+ - - '>='
110
109
  - !ruby/object:Gem::Version
111
110
  version: '0'
112
111
  required_rubygems_version: !ruby/object:Gem::Requirement
113
- none: false
114
112
  requirements:
115
- - - ! '>='
113
+ - - '>='
116
114
  - !ruby/object:Gem::Version
117
115
  version: '0'
118
116
  requirements: []
119
117
  rubyforge_project:
120
- rubygems_version: 1.8.24
118
+ rubygems_version: 2.0.5
121
119
  signing_key:
122
- specification_version: 3
120
+ specification_version: 4
123
121
  summary: Ruby gem for integration with Zoho CRM
124
122
  test_files:
125
123
  - test/test_helper.rb
124
+ - test/zoro/account_test.rb
126
125
  - test/zoro/api_test.rb
126
+ - test/zoro/field_name_test.rb
127
127
  - test/zoro/lead_test.rb
128
+ - test/zoro/record_test.rb