mscrmrails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/lib/mscrmrails.rb +97 -0
- data/lib/mscrmrails/version.rb +3 -0
- data/mscrmrails.gemspec +29 -0
- metadata +151 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brent's Retina Mac
|
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,48 @@
|
|
1
|
+
# Mscrmrails
|
2
|
+
|
3
|
+
Simple gem to access MSCRM 3.0 data in ruby
|
4
|
+
|
5
|
+
_WIP: update, delete
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'mscrmrails'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install mscrmrails
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
config/initializers/mscrm.rb
|
24
|
+
|
25
|
+
Mscrmrails.configure do |c|
|
26
|
+
c.server = 'crm.example.com'
|
27
|
+
c.username = 'username'
|
28
|
+
c.domain = 'domain'
|
29
|
+
c.password = 'password'
|
30
|
+
end
|
31
|
+
|
32
|
+
@client = Mscrmrails::CRM.new
|
33
|
+
|
34
|
+
@lead_id = @client.create 'lead', { :attributes => { :name => 'Name', :company => 'Company', :email => 'email@email.com' } }
|
35
|
+
|
36
|
+
@leads = fetch 'lead', {
|
37
|
+
:limit => 100,
|
38
|
+
:fields => ['firstname','lastname','companyname','createdon'],
|
39
|
+
:conditions => { 'or' => [['firstname','Firstname'],['lastname','Lastname']] }
|
40
|
+
}
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/mscrmrails.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require "mscrmrails/version"
|
2
|
+
require "savon"
|
3
|
+
require "crack"
|
4
|
+
|
5
|
+
module Mscrmrails
|
6
|
+
module_function
|
7
|
+
|
8
|
+
class Configuration
|
9
|
+
attr_accessor :server, :port, :server_path, :domain, :username, :password, :soap_header, :guid
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
self.server = nil
|
13
|
+
self.port = '5555'
|
14
|
+
self.soap_header = '<soap:Header></soap:Header>'
|
15
|
+
self.server_path = 'mscrmservices/2006/crmservice.asmx'
|
16
|
+
self.domain = nil
|
17
|
+
self.username = nil
|
18
|
+
self.password = nil
|
19
|
+
self.guid = nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class CRM
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
HTTPI::Adapter.use = :net_http
|
27
|
+
|
28
|
+
Savon.configure do |c|
|
29
|
+
c.env_namespace = :soap
|
30
|
+
c.raise_errors = false
|
31
|
+
c.pretty_print_xml = true
|
32
|
+
#c.log = false
|
33
|
+
end
|
34
|
+
|
35
|
+
@@client = Savon::Client.new do |wsdl, http|
|
36
|
+
wsdl.document = "http://#{Mscrmrails.config.server}:#{Mscrmrails.config.port}/#{Mscrmrails.config.server_path}" + '?wsdl'
|
37
|
+
wsdl.element_form_default = :qualified
|
38
|
+
http.auth.ntlm(Mscrmrails.config.username, Mscrmrails.config.domain, Mscrmrails.config.password)
|
39
|
+
http.auth.ssl.verify_mode = :none
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_fetchxml entity, options = {}
|
44
|
+
limit = options[:limit] ? options[:limit] : 200
|
45
|
+
xml = "<fetch mapping='logical' page='1' count='"+limit.to_s+"'><entity name='" + entity + "'>"
|
46
|
+
|
47
|
+
options[:fields].each do |attribute|
|
48
|
+
xml += "<attribute name='" + attribute + "'/>"
|
49
|
+
end
|
50
|
+
|
51
|
+
options[:conditions].each do |condition, op|
|
52
|
+
xml += "<filter type='" + condition + "'>"
|
53
|
+
op.each do |value|
|
54
|
+
#xml += value.inspect
|
55
|
+
o = value[2] ? value[2] : 'eq'
|
56
|
+
xml += "<condition attribute='" + value[0] + "' operator='" + o + "' value='" + value[1] + "' />"
|
57
|
+
end
|
58
|
+
xml += "</filter>"
|
59
|
+
end
|
60
|
+
xml += "</entity></fetch>"
|
61
|
+
return xml
|
62
|
+
end
|
63
|
+
|
64
|
+
def fetch entityname, options = {}
|
65
|
+
result = @@client.request :fetch do |soap|
|
66
|
+
#soap.header = ''#AUTH_HEADER
|
67
|
+
|
68
|
+
body = Hash.new
|
69
|
+
body["fetchXml"] = build_fetchxml entityname, options
|
70
|
+
soap.body = body
|
71
|
+
end
|
72
|
+
#return result
|
73
|
+
results = Crack::XML.parse(result.body[:fetch_result])["resultset"]["result"]
|
74
|
+
results.class == Hash ? [results] : results
|
75
|
+
end
|
76
|
+
|
77
|
+
def create entityname, options = {}
|
78
|
+
result = @@client.request :create , type: entityname do |soap|
|
79
|
+
xml = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><entity xmlns='http://schemas.microsoft.com/crm/2006/WebServices' xsi:type='#{entityname}'>"
|
80
|
+
options[:attributes].each do |key,value|
|
81
|
+
xml += "<#{key}>#{value}</#{key}>"
|
82
|
+
end
|
83
|
+
xml += "</entity></soap:Body></soap:Envelope>"
|
84
|
+
soap.xml = xml
|
85
|
+
end
|
86
|
+
result.body[:create_result]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.configure
|
91
|
+
yield(config) if block_given?
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.config
|
95
|
+
@configuration ||= Configuration.new
|
96
|
+
end
|
97
|
+
end
|
data/mscrmrails.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mscrmrails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mscrmrails"
|
8
|
+
spec.version = Mscrmrails::VERSION
|
9
|
+
spec.authors = ["Brent Weber"]
|
10
|
+
spec.email = ["bweber@spinuplabs.com"]
|
11
|
+
spec.summary = 'MSCRM 3.0 Connection'
|
12
|
+
spec.description = 'Gem that makes it easier to connect a rails application to a mscrm 3.0 installation.'
|
13
|
+
spec.homepage = ""
|
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
|
+
|
24
|
+
# Dependencies
|
25
|
+
spec.add_dependency('savon', '>= 0') #~>1.2.0')
|
26
|
+
spec.add_dependency('json', '>= 0')
|
27
|
+
spec.add_dependency('crack', '>= 0')
|
28
|
+
spec.add_dependency('hash_extension', '>= 0')
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mscrmrails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brent Weber
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-19 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
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: savon
|
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: json
|
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
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: crack
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: hash_extension
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Gem that makes it easier to connect a rails application to a mscrm 3.0
|
111
|
+
installation.
|
112
|
+
email:
|
113
|
+
- bweber@spinuplabs.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- lib/mscrmrails.rb
|
124
|
+
- lib/mscrmrails/version.rb
|
125
|
+
- mscrmrails.gemspec
|
126
|
+
homepage: ''
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 1.8.25
|
148
|
+
signing_key:
|
149
|
+
specification_version: 3
|
150
|
+
summary: MSCRM 3.0 Connection
|
151
|
+
test_files: []
|