uniqush-rb 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/.gitignore +1 -0
- data/lib/uniqush/restful_client.rb +34 -0
- data/lib/uniqush/version.rb +1 -1
- data/lib/uniqush.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support.rb +16 -0
- data/spec/uniqush/client_spec.rb +0 -17
- data/spec/uniqush/restul_client_spec.rb +28 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f708c4f51493c8cba5a1159c3d4b2cf2a983e999
|
4
|
+
data.tar.gz: 5da4f9470d6f6e3c66cc0033a9e43a503f13ec50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b64ccaffeadcefa168634dea00de7b0b67a9ad73a208276a8a7e1f3b347606ddcb352aa43282b2cbecb5f68c3faad470d385bbd1b44a36c0876743fdd0ae4467
|
7
|
+
data.tar.gz: 5909e315dac60a9f147b81143f413dea277cea16886bb9838aa6fde6fae120f6000d1d7296d186f1a6100e89b4965f19fd1282c6e0e2f22d3f451016dc74806c
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "rest-client"
|
2
|
+
|
3
|
+
module Uniqush
|
4
|
+
class RestfulClient
|
5
|
+
ENDPOINTS = {
|
6
|
+
version: [:get, "version"],
|
7
|
+
stop: [:post, "stop"],
|
8
|
+
add_service: [:post, "push_service_providers"],
|
9
|
+
remove_service: [:delete, "push_service_providers"],
|
10
|
+
subscribe_device: [:post, "subscribers"],
|
11
|
+
unsubscribe_device: [:delete, "subscribers"],
|
12
|
+
push: [:post, "push"]
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
def initialize(base_url)
|
16
|
+
@client = rest_client(base_url)
|
17
|
+
end
|
18
|
+
|
19
|
+
ENDPOINTS.each do |method, (http_method, url)|
|
20
|
+
define_method method do |params = {}, extras = {}|
|
21
|
+
if [:post, :put, :patch].include?(http_method)
|
22
|
+
args = [params.to_json, extras]
|
23
|
+
else
|
24
|
+
args = [{params: params}.merge(extras)]
|
25
|
+
end
|
26
|
+
@client[url].send(http_method, *args)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def rest_client(url)
|
31
|
+
RestClient::Resource.new(url)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/uniqush/version.rb
CHANGED
data/lib/uniqush.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/support.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
RSpec::Matchers.define(:request) do |method, url|
|
2
|
+
match do |action|
|
3
|
+
@stub = stub_request(method, url)
|
4
|
+
@stub = @stub.with(@with) unless @with.nil?
|
5
|
+
action.call
|
6
|
+
expect(@stub).to have_been_requested
|
7
|
+
end
|
8
|
+
|
9
|
+
chain(:with) do |options|
|
10
|
+
@with = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def supports_block_expectations?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
data/spec/uniqush/client_spec.rb
CHANGED
@@ -5,23 +5,6 @@ describe Uniqush::Client do
|
|
5
5
|
let(:client) { described_class.new(base_url) }
|
6
6
|
let(:a_hash) { {foo: "bar", baz: "bam"} }
|
7
7
|
|
8
|
-
RSpec::Matchers.define(:request) do |method, url|
|
9
|
-
match do |action|
|
10
|
-
@stub = stub_request(method, url)
|
11
|
-
@stub = @stub.with(@with) unless @with.nil?
|
12
|
-
action.call
|
13
|
-
expect(@stub).to have_been_requested
|
14
|
-
end
|
15
|
-
|
16
|
-
chain(:with) do |options|
|
17
|
-
@with = options
|
18
|
-
end
|
19
|
-
|
20
|
-
def supports_block_expectations?
|
21
|
-
true
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
8
|
describe "services" do
|
26
9
|
it "adds service" do
|
27
10
|
expect { client.add_service(a_hash) }.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Uniqush::RestfulClient do
|
4
|
+
let(:base_url) { "http://yourinstall.com" }
|
5
|
+
let(:client) { described_class.new(base_url) }
|
6
|
+
let(:a_hash) { {foo: "bar", baz: "bam"} }
|
7
|
+
|
8
|
+
describe "services" do
|
9
|
+
it "adds service" do
|
10
|
+
expect { client.add_service(a_hash) }.
|
11
|
+
to request(:post, "#{base_url}/push_service_providers").with(body: a_hash.to_json)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "subscriptions" do
|
16
|
+
it "subscribes" do
|
17
|
+
expect { client.subscribe_device(a_hash) }.
|
18
|
+
to request(:post, "#{base_url}/subscribers").with(body: a_hash.to_json)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "pushing" do
|
23
|
+
it "pushes" do
|
24
|
+
expect { client.push(a_hash) }.
|
25
|
+
to request(:post, "#{base_url}/push").with(body: a_hash.to_json)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uniqush-rb
|
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
|
- Rafael Bandeira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -88,6 +88,7 @@ executables: []
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
+
- ".gitignore"
|
91
92
|
- Gemfile
|
92
93
|
- Gemfile.lock
|
93
94
|
- LICENSE.txt
|
@@ -95,9 +96,12 @@ files:
|
|
95
96
|
- Rakefile
|
96
97
|
- lib/uniqush.rb
|
97
98
|
- lib/uniqush/client.rb
|
99
|
+
- lib/uniqush/restful_client.rb
|
98
100
|
- lib/uniqush/version.rb
|
99
101
|
- spec/spec_helper.rb
|
102
|
+
- spec/support.rb
|
100
103
|
- spec/uniqush/client_spec.rb
|
104
|
+
- spec/uniqush/restul_client_spec.rb
|
101
105
|
- uniqush-rb.gemspec
|
102
106
|
homepage: https://github.com/rafaelbandeira3/uniqush-rb
|
103
107
|
licenses:
|
@@ -125,5 +129,7 @@ specification_version: 4
|
|
125
129
|
summary: Client for uniqush-push
|
126
130
|
test_files:
|
127
131
|
- spec/spec_helper.rb
|
132
|
+
- spec/support.rb
|
128
133
|
- spec/uniqush/client_spec.rb
|
134
|
+
- spec/uniqush/restul_client_spec.rb
|
129
135
|
has_rdoc:
|