simple_desk 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 +4 -4
- data/lib/simple_desk.rb +46 -2
- data/lib/simple_desk/version.rb +1 -1
- data/simple_desk.gemspec +2 -0
- data/spec/my_spec.rb +37 -0
- data/spec/spec_helper.rb +9 -0
- metadata +36 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23a89481be98dbf5f3d4adb26c78403c547aa0bb
|
4
|
+
data.tar.gz: c780cdff43b76cf712eb93db94eadf1cf442dd7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec91324c746ba75177739ac6acd65083cc0b357f453307f113ed03fe7f58cdebede988cb35d78dc4e84a558f78be3187438a90465661bea7829513fb68f759a9
|
7
|
+
data.tar.gz: 87e71c3650a3f950ce578fa0059c71dd1eea90b098bb711acae4b3d3cdc8ee9f31be78249e2756301343ad80367ac95875e6cbb8d193551e41ec7e57e387a7e8
|
data/lib/simple_desk.rb
CHANGED
@@ -1,5 +1,49 @@
|
|
1
1
|
require "simple_desk/version"
|
2
|
+
require "net/http"
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
class Api
|
6
|
+
BASE_URL = "https://www.getsimpledesk.com"
|
7
|
+
TOKEN = ENV['SIMPLE_DESK_TOKEN'] || "ucMKQtZ0CQkgfGzTj6lOJe2VRvoRHM8z"
|
8
|
+
|
9
|
+
def add_customer(params)
|
10
|
+
uri = URI.parse(post_url("add_customer"))
|
11
|
+
response = Net::HTTP.post_form(uri, params)
|
12
|
+
end
|
13
|
+
alias_method :update_customer, :add_customer
|
14
|
+
|
15
|
+
|
16
|
+
def build_url(post_type = nil, params=nil)
|
17
|
+
url = post_url(post_type)
|
18
|
+
|
19
|
+
if params
|
20
|
+
string = ''
|
21
|
+
url << "&"
|
22
|
+
params.each { |k,v| string << "#{k}=#{v}&" }
|
23
|
+
|
24
|
+
url << string
|
25
|
+
url = url[0...-1] if (url[-1] == '&')
|
26
|
+
end
|
27
|
+
|
28
|
+
return url
|
29
|
+
end
|
30
|
+
|
31
|
+
def post_url(post_type)
|
32
|
+
if post_type == nil
|
33
|
+
"#{BASE_URL}?token=#{TOKEN}"
|
34
|
+
else
|
35
|
+
case post_type
|
36
|
+
when "message_customer"
|
37
|
+
"#{BASE_URL}/api_send_message?token=#{TOKEN}"
|
38
|
+
when "add_customer" || "update_customer"
|
39
|
+
"#{BASE_URL}/api_add_customer?token=#{TOKEN}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def message_customer(message_and_phone_number)
|
45
|
+
uri = URI.parse(post_url("message_customer"))
|
46
|
+
response = Net::HTTP.post_form(uri, message_and_phone_number)
|
47
|
+
end
|
2
48
|
|
3
|
-
module SimpleDesk
|
4
|
-
# Your code goes here...
|
5
49
|
end
|
data/lib/simple_desk/version.rb
CHANGED
data/simple_desk.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_development_dependency "rspec"
|
22
|
+
spec.add_development_dependency "pry"
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
24
|
spec.add_development_dependency "rake"
|
23
25
|
end
|
data/spec/my_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "simple_desk"
|
3
|
+
|
4
|
+
describe Api do
|
5
|
+
before :each do
|
6
|
+
@api = Api.new
|
7
|
+
@phone = {phone_number: "555#{Random.rand(10_000_000 - 1_000_000)}"}
|
8
|
+
@user = {first_name: "Elijah", last_name: "Murray"}.merge!(@phone)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#build_url" do
|
12
|
+
it "build_url returns a string" do
|
13
|
+
@api.build_url.should eql "https://www.getsimpledesk.com?token=ucMKQtZ0CQkgfGzTj6lOJe2VRvoRHM8z"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#add_customer" do
|
18
|
+
it "add customer successfully" do
|
19
|
+
# skip("disabled to not call API")
|
20
|
+
request = @api.add_customer(@user)
|
21
|
+
request.response.code.should eql "200"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#message_customer" do
|
26
|
+
it "message customer successfully" do
|
27
|
+
# skip("disabled to not call API")
|
28
|
+
message = "Hi customer!"
|
29
|
+
to = {to: @phone[:phone_number]}
|
30
|
+
params = {text: message}.merge!(to)
|
31
|
+
request = @api.message_customer(params)
|
32
|
+
request.response.code.should eql "200"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_desk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elijah Murray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,6 +81,8 @@ files:
|
|
53
81
|
- lib/simple_desk.rb
|
54
82
|
- lib/simple_desk/version.rb
|
55
83
|
- simple_desk.gemspec
|
84
|
+
- spec/my_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
56
86
|
homepage: http://elijahish.com
|
57
87
|
licenses:
|
58
88
|
- MIT
|
@@ -73,9 +103,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
103
|
version: '0'
|
74
104
|
requirements: []
|
75
105
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.1.9
|
77
107
|
signing_key:
|
78
108
|
specification_version: 4
|
79
109
|
summary: Provides a clean and simple gem to connect to Simple Desk
|
80
|
-
test_files:
|
81
|
-
|
110
|
+
test_files:
|
111
|
+
- spec/my_spec.rb
|
112
|
+
- spec/spec_helper.rb
|