inside_sales 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 +3 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/inside_sales.gemspec +21 -0
- data/lib/inside_sales/version.rb +3 -0
- data/lib/inside_sales.rb +52 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "inside_sales/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "inside_sales"
|
7
|
+
s.version = InsideSales::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Michael Guterl"]
|
10
|
+
s.email = ["mguterl@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{InsideSales API}
|
13
|
+
s.description = %q{InsideSales API}
|
14
|
+
|
15
|
+
s.rubyforge_project = "inside_sales"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
data/lib/inside_sales.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module InsideSales
|
2
|
+
|
3
|
+
REST_API_URL = 'https://#{@subdomain}.insidesales.com/do=noauth/rest/service'
|
4
|
+
|
5
|
+
class Client
|
6
|
+
|
7
|
+
Error = Class.new(StandardError)
|
8
|
+
AuthenticationError = Class.new(Error)
|
9
|
+
|
10
|
+
attr_reader :endpoint_url
|
11
|
+
|
12
|
+
def initialize(subdomain, username, password, token)
|
13
|
+
@username, @password, @token, @subdomain = username, password, token, subdomain
|
14
|
+
@endpoint_url ||= eval('"' + REST_API_URL + '"')
|
15
|
+
end
|
16
|
+
|
17
|
+
# This is a special type of request that is not handled via
|
18
|
+
# method_missing because of the logic required to set the cookies.
|
19
|
+
def login
|
20
|
+
response = request(:login, [@username, @password, @token])
|
21
|
+
if response == "false"
|
22
|
+
raise AuthenticationError, "could not authenticate, please check your credentials"
|
23
|
+
else
|
24
|
+
@cookies = response.cookies
|
25
|
+
response
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# dynamically dispatch methods to the web service
|
30
|
+
def method_missing(meth, *args, &block)
|
31
|
+
request(meth.to_s.camelize(:lower), [*args])
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Unfortunately the InsideSales API does not always return valid
|
37
|
+
# JSON, so we have to work around it a bit.
|
38
|
+
def request(operation, parameters)
|
39
|
+
response = RestClient.post(endpoint_url, { :operation => operation, :parameters => parameters }.to_json, { :cookies => @cookies })
|
40
|
+
parsed = JSON.parse response
|
41
|
+
if parsed.is_a?(Hash) && parsed.has_key?("exception")
|
42
|
+
raise Error, parsed["exception"]["string"]
|
43
|
+
else
|
44
|
+
parsed
|
45
|
+
end
|
46
|
+
rescue JSON::ParserError
|
47
|
+
response
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inside_sales
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Guterl
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-25 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: InsideSales API
|
23
|
+
email:
|
24
|
+
- mguterl@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- Rakefile
|
35
|
+
- inside_sales.gemspec
|
36
|
+
- lib/inside_sales.rb
|
37
|
+
- lib/inside_sales/version.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: ""
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
hash: 3
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: inside_sales
|
68
|
+
rubygems_version: 1.3.7
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: InsideSales API
|
72
|
+
test_files: []
|
73
|
+
|