v_tiger 0.0.1.3
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 +6 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +8 -0
- data/Guardfile +8 -0
- data/Rakefile +1 -0
- data/lib/v_tiger/api.rb +29 -0
- data/lib/v_tiger/query.rb +31 -0
- data/lib/v_tiger/version.rb +3 -0
- data/lib/v_tiger.rb +46 -0
- data/spec/product_spec.rb +5 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/include_hash.rb +7 -0
- data/spec/vtiger_query_spec.rb +32 -0
- data/spec/vtiger_spec.rb +94 -0
- data/v_tiger.gemspec +26 -0
- metadata +110 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.2@vtr
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/v_tiger/api.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module VTiger::API
|
2
|
+
def list_types
|
3
|
+
get('listtypes')['result']['types']
|
4
|
+
end
|
5
|
+
|
6
|
+
def describe(element_type)
|
7
|
+
get('describe', :elementType => element_type)['result']
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(elementType, element = {})
|
11
|
+
post('create', :elementType => elementType, :element => element.to_json)
|
12
|
+
end
|
13
|
+
|
14
|
+
def retrieve(id)
|
15
|
+
get('retrieve', :id => id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def query(query_string)
|
19
|
+
get('query', :query => query_string)
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(element)
|
23
|
+
post('update', :element => element)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete(id)
|
27
|
+
post('delete', :id => id)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module VTiger::Query
|
2
|
+
|
3
|
+
def build_query(objectType, options = {})
|
4
|
+
@objectType = objectType
|
5
|
+
@options = options
|
6
|
+
@query = get('query', :query => query_string)
|
7
|
+
@query['result'] += get_more while more_results_needed?
|
8
|
+
@query
|
9
|
+
end
|
10
|
+
|
11
|
+
def query_string(options = {})
|
12
|
+
limit = options[:limit] || @options[:limit]
|
13
|
+
[].tap do |query|
|
14
|
+
query << 'select'
|
15
|
+
query << '*'
|
16
|
+
query << "from #{@objectType}"
|
17
|
+
query << "limit #{limit}" if limit
|
18
|
+
query << ';'
|
19
|
+
end.join(' ')
|
20
|
+
end
|
21
|
+
|
22
|
+
def more_results_needed?
|
23
|
+
@options[:limit].present? && @query['result'].count < @options[:limit]
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_more
|
27
|
+
offset = @query['result'].count
|
28
|
+
new_limit = @options[:limit] - offset
|
29
|
+
get('query', :query => query_string(:limit => "#{offset}, #{new_limit}"))['result']
|
30
|
+
end
|
31
|
+
end
|
data/lib/v_tiger.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "v_tiger/version"
|
2
|
+
require "v_tiger/api"
|
3
|
+
# require "vtiger/query"
|
4
|
+
|
5
|
+
require 'httparty'
|
6
|
+
require 'json'
|
7
|
+
YAML::ENGINE.yamler = "syck"
|
8
|
+
|
9
|
+
require 'active_support/time'
|
10
|
+
require 'active_support/core_ext/numeric'
|
11
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
12
|
+
require 'active_support/core_ext/hash/slice'
|
13
|
+
|
14
|
+
class VTiger
|
15
|
+
cattr_accessor :user, :key, :uri
|
16
|
+
include VTiger::API
|
17
|
+
# include VTiger::Query
|
18
|
+
|
19
|
+
def self.config(config = {})
|
20
|
+
VTiger.user = config[:user]
|
21
|
+
VTiger.key = config[:key]
|
22
|
+
VTiger.uri = config[:uri]
|
23
|
+
end
|
24
|
+
|
25
|
+
def get(operation, query = {})
|
26
|
+
query = {:operation => operation, :sessionName => VTiger.session}.merge(query)
|
27
|
+
HTTParty.get(VTiger.uri, :query => query).parsed_response
|
28
|
+
end
|
29
|
+
|
30
|
+
def post(operation, body = {})
|
31
|
+
body = {:operation => operation, :sessionName => VTiger.session}.merge(body)
|
32
|
+
HTTParty.post(VTiger.uri, :body => body).parsed_response
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def self.session
|
38
|
+
unless @session && @challenge['expireTime'] > 30.seconds.from_now.to_i
|
39
|
+
@challenge = HTTParty.get(uri, :query => {:operation => 'getchallenge', :username => user}).parsed_response['result']
|
40
|
+
digest = "#{@challenge['token']}#{key}"
|
41
|
+
access_key = Digest::MD5.hexdigest(digest)
|
42
|
+
@session = HTTParty.post(uri, {:body => {:operation => 'login', :username => user, :accessKey => access_key}}).parsed_response['result']['sessionName']
|
43
|
+
end
|
44
|
+
@session
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'v_tiger' # and any other gems you need
|
5
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
# some (optional) config here
|
9
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "VTiger::Query" do
|
4
|
+
before(:all) do
|
5
|
+
VTiger.config(:user => 'admin', :key => 'dH1WLzo4utYOpXx9', :uri => 'http://crm.ihswebdesign.com/webservice.php')
|
6
|
+
@api = VTiger.new
|
7
|
+
end
|
8
|
+
describe "#query" do
|
9
|
+
context "with just the objectType " do
|
10
|
+
before(:all) do
|
11
|
+
@query = @api.query('Products')
|
12
|
+
end
|
13
|
+
it "should return somthing" do
|
14
|
+
@query['result'].should be
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should default to 100 objects" do
|
18
|
+
@query['result'].count.should equal(100)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with a limit" do
|
23
|
+
it "should not return more than the limit" do
|
24
|
+
@api.query('Products', :limit => 50)['result'].count.should_not > 50
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return more than 100 is more than default" do
|
28
|
+
@api.query('Products', :limit => 150)['result'].count.should > 100
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/vtiger_spec.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "VTiger" do
|
4
|
+
before(:all) do
|
5
|
+
VTiger.config(:user => 'admin', :key => 'dH1WLzo4utYOpXx9', :uri => 'http://crm.ihswebdesign.com/webservice.php')
|
6
|
+
@api = VTiger.new
|
7
|
+
end
|
8
|
+
describe ".config" do
|
9
|
+
context "should set user, key, and uri class variables" do
|
10
|
+
it "user is admin" do
|
11
|
+
VTiger.user.should == 'admin'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "key is dH1WLzo4utYOpXx9" do
|
15
|
+
VTiger.key.should == 'dH1WLzo4utYOpXx9'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "uri is http://crm.ihswebdesign.com/webservice.php" do
|
19
|
+
VTiger.uri.should == 'http://crm.ihswebdesign.com/webservice.php'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#create" do
|
25
|
+
context " with a valid object" do
|
26
|
+
before(:all) do
|
27
|
+
@attributes = {'productname' => 'Title of Product', 'manufacturer' => 'Broyhill'}
|
28
|
+
@create = @api.create('Products', @attributes)
|
29
|
+
end
|
30
|
+
it "should return success" do
|
31
|
+
@create['success'].should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return an VTigerObject that matches what we sent" do
|
35
|
+
@create['result'].should include_hash(@attributes)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#retrieve" do
|
41
|
+
context " with a valid object" do
|
42
|
+
before(:all) do
|
43
|
+
@attributes = {'productname' => 'Title of Product', 'manufacturer' => 'Broyhill'}
|
44
|
+
id = @api.create('Products', @attributes)['result']['id']
|
45
|
+
@retrieve = @api.retrieve(id)
|
46
|
+
end
|
47
|
+
it "should return success" do
|
48
|
+
@retrieve['success'].should be_true
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return an VTigerObject that matches what we sent" do
|
52
|
+
@retrieve['result'].should include_hash(@attributes)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#query" do
|
58
|
+
before(:all) do
|
59
|
+
@query = @api.query('select * from Products;')
|
60
|
+
end
|
61
|
+
it "should return success" do
|
62
|
+
@query['success'].should be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return an array of objects" do
|
66
|
+
@query['result'].should be_a(Array)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#list_types" do
|
71
|
+
it "should include Products" do
|
72
|
+
@api.list_types.should include('Products')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#describe" do
|
77
|
+
context " Product" do
|
78
|
+
it "should have a label with Products" do
|
79
|
+
@api.describe('Products')['label'].should == "Products"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe ".session" do
|
86
|
+
it "should be present" do
|
87
|
+
VTiger.class_eval{session}.should be
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should persist" do
|
91
|
+
VTiger.class_eval{session}.should == VTiger.class_eval{session}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/v_tiger.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "v_tiger/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "v_tiger"
|
7
|
+
s.version = VTiger::VERSION
|
8
|
+
s.authors = ["Torey Heinz"]
|
9
|
+
s.email = ["torey@ihswebdesign.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{A very Thin wrapper around the VTiger Web Services API}
|
12
|
+
s.description = %q{A very Thin wrapper around the VTiger Web Services API}
|
13
|
+
|
14
|
+
s.rubyforge_project = "v_tiger"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency('httparty')
|
22
|
+
s.add_dependency('activesupport')
|
23
|
+
s.add_dependency('i18n')
|
24
|
+
|
25
|
+
s.add_development_dependency('rspec')
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: v_tiger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Torey Heinz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-29 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: &70336370116520 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70336370116520
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
requirement: &70336370116100 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70336370116100
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: i18n
|
38
|
+
requirement: &70336364465500 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70336364465500
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &70336364465080 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70336364465080
|
58
|
+
description: A very Thin wrapper around the VTiger Web Services API
|
59
|
+
email:
|
60
|
+
- torey@ihswebdesign.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rspec
|
67
|
+
- .rvmrc
|
68
|
+
- Gemfile
|
69
|
+
- Guardfile
|
70
|
+
- Rakefile
|
71
|
+
- lib/v_tiger.rb
|
72
|
+
- lib/v_tiger/api.rb
|
73
|
+
- lib/v_tiger/query.rb
|
74
|
+
- lib/v_tiger/version.rb
|
75
|
+
- spec/product_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- spec/support/include_hash.rb
|
78
|
+
- spec/vtiger_query_spec.rb
|
79
|
+
- spec/vtiger_spec.rb
|
80
|
+
- v_tiger.gemspec
|
81
|
+
homepage: ''
|
82
|
+
licenses: []
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
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
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project: v_tiger
|
101
|
+
rubygems_version: 1.8.6
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: A very Thin wrapper around the VTiger Web Services API
|
105
|
+
test_files:
|
106
|
+
- spec/product_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
- spec/support/include_hash.rb
|
109
|
+
- spec/vtiger_query_spec.rb
|
110
|
+
- spec/vtiger_spec.rb
|