karmacrm 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +7 -0
- data/examples/configure_example.rb +11 -0
- data/karmacrm.gemspec +22 -0
- data/lib/karmacrm.rb +7 -0
- data/lib/karmacrm/base.rb +55 -0
- data/lib/karmacrm/company.rb +4 -0
- data/lib/karmacrm/contact.rb +5 -0
- data/lib/karmacrm/deal.rb +5 -0
- data/lib/karmacrm/note.rb +12 -0
- data/lib/karmacrm/user.rb +4 -0
- data/lib/karmacrm/version.rb +3 -0
- data/test/company_test.rb +16 -0
- data/test/contact_test.rb +18 -0
- data/test/test_config.yml +3 -0
- data/test/test_helper.rb +10 -0
- metadata +116 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$:.unshift File.join(File.expand_path("../..", __FILE__), "lib")
|
2
|
+
|
3
|
+
require "karmacrm"
|
4
|
+
|
5
|
+
Karmacrm::Base.config do |conf|
|
6
|
+
conf.site = "http://localhost:3000"
|
7
|
+
conf.api_key = 'eJogN2yuam5YV-v2_l3f'
|
8
|
+
end
|
9
|
+
|
10
|
+
# Can be set directly too
|
11
|
+
Karmacrm::Base.api_key = 'eJogN2yuam5YV-v2_l3f'
|
data/karmacrm.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "karmacrm/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "karmacrm"
|
7
|
+
s.version = Karmacrm::VERSION
|
8
|
+
s.authors = ["John Paul Narowski"]
|
9
|
+
s.email = ["jp@karmacrm.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{KarmaCRM client library}
|
12
|
+
s.description = %q{KarmaCRM API client library}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
# specify any dependencies here
|
20
|
+
s.add_dependency "activeresource", "2.3.12"
|
21
|
+
s.add_dependency "rake", "0.8.7"
|
22
|
+
end
|
data/lib/karmacrm.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "active_resource"
|
2
|
+
|
3
|
+
module Karmacrm
|
4
|
+
class Base < ActiveResource::Base
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def api_key=(api_key)
|
8
|
+
@@api_key = api_key
|
9
|
+
end
|
10
|
+
|
11
|
+
def api_key
|
12
|
+
@@api_key ||= ""
|
13
|
+
end
|
14
|
+
|
15
|
+
def api_version
|
16
|
+
@@api_version ||= "1"
|
17
|
+
end
|
18
|
+
|
19
|
+
def format
|
20
|
+
@@format ||= ActiveResource::Formats::JsonFormat
|
21
|
+
end
|
22
|
+
|
23
|
+
def site=(site_url)
|
24
|
+
self.prefix = "/api/v#{api_version}/"
|
25
|
+
self.include_root_in_json = true
|
26
|
+
super(site_url)
|
27
|
+
end
|
28
|
+
|
29
|
+
def config
|
30
|
+
yield self
|
31
|
+
end
|
32
|
+
|
33
|
+
alias :instantiate_collection_orig :instantiate_collection
|
34
|
+
|
35
|
+
def instantiate_collection(collection, prefix_options = {})
|
36
|
+
collection = collection[collection_name] if collection.is_a? Hash
|
37
|
+
instantiate_collection_orig(collection, prefix_options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def find(*args)
|
41
|
+
scope = args.slice!(0)
|
42
|
+
options = args.slice!(0) || {}
|
43
|
+
options.merge!({:params => {:api_key => api_key}})
|
44
|
+
|
45
|
+
items = super(scope, options)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def save
|
50
|
+
prefix_options[:api_key] = self.class.api_key
|
51
|
+
super
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "test/test_helper"
|
2
|
+
require "karmacrm/company"
|
3
|
+
|
4
|
+
module Karmacrm
|
5
|
+
class CompanyTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_create
|
10
|
+
all_companies = Company.find(:all)
|
11
|
+
company = Company.new(:name => 'Test company')
|
12
|
+
company.save
|
13
|
+
assert_equal all_companies.length + 1, Company.find(:all).length
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "karmacrm/contact"
|
3
|
+
|
4
|
+
module Karmacrm
|
5
|
+
class ContactTest < Test::Unit::TestCase
|
6
|
+
def test_create
|
7
|
+
all = Contact.find(:all)
|
8
|
+
first_name = "Test"
|
9
|
+
last_name = "Contact"
|
10
|
+
contact = Contact.create(:first_name => first_name, :last_name => last_name)
|
11
|
+
assert contact.save
|
12
|
+
|
13
|
+
assert_equal all.length + 1, Contact.find(:all).length
|
14
|
+
assert_equal first_name, contact.first_name
|
15
|
+
assert_equal last_name, contact.last_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "test/unit"
|
3
|
+
require "karmacrm"
|
4
|
+
|
5
|
+
test_cfg = YAML.load_file(File.join(File.expand_path("../", __FILE__), "test_config.yml"))
|
6
|
+
Karmacrm::Base.config do |config|
|
7
|
+
config.site = test_cfg[:site]
|
8
|
+
config.api_key = test_cfg[:api_key]
|
9
|
+
config.logger = Logger.new(STDOUT) if test_cfg[:verbose] == true
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: karmacrm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- John Paul Narowski
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-11-27 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activeresource
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - "="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 27
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 3
|
32
|
+
- 12
|
33
|
+
version: 2.3.12
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - "="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 49
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 8
|
48
|
+
- 7
|
49
|
+
version: 0.8.7
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
description: KarmaCRM API client library
|
53
|
+
email:
|
54
|
+
- jp@karmacrm.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- Rakefile
|
65
|
+
- examples/configure_example.rb
|
66
|
+
- karmacrm.gemspec
|
67
|
+
- lib/karmacrm.rb
|
68
|
+
- lib/karmacrm/base.rb
|
69
|
+
- lib/karmacrm/company.rb
|
70
|
+
- lib/karmacrm/contact.rb
|
71
|
+
- lib/karmacrm/deal.rb
|
72
|
+
- lib/karmacrm/note.rb
|
73
|
+
- lib/karmacrm/user.rb
|
74
|
+
- lib/karmacrm/version.rb
|
75
|
+
- test/company_test.rb
|
76
|
+
- test/contact_test.rb
|
77
|
+
- test/test_config.yml
|
78
|
+
- test/test_helper.rb
|
79
|
+
homepage: ""
|
80
|
+
licenses: []
|
81
|
+
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.8.11
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: KarmaCRM client library
|
112
|
+
test_files:
|
113
|
+
- test/company_test.rb
|
114
|
+
- test/contact_test.rb
|
115
|
+
- test/test_config.yml
|
116
|
+
- test/test_helper.rb
|