bup_bup_rb 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.
- checksums.yaml +7 -0
- data/lib/bup_bup_rb.rb +1 -0
- data/lib/bup_bup_rb/bupbup_error.rb +5 -0
- data/lib/bup_bup_rb/client.rb +50 -0
- data/lib/bup_bup_rb/resources/device.rb +50 -0
- data/lib/bup_bup_rb/resources/notification.rb +33 -0
- data/lib/bup_bup_rb/version.rb +3 -0
- metadata +91 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 6524a8588ebb2d9a6c758f04d2a4e05c15eb8712
|
|
4
|
+
data.tar.gz: 84b956f7c25ad1c130c98d15124434d271e21489
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: cdf4f20c2a7083fce14bade8b41af95e816add365d9e2edd1a138cb7fdd688d7569f29c305e5f2f2350f8aa165cb4ef8d70c2d3ec3104134899398632d5a920c
|
|
7
|
+
data.tar.gz: 314af476222194a1033dd977f8266f744932c0e7116a646dd1c46c029146189c03be3b2e43da8bfe7f8ff95a0298da48d36783655d1c1b32ff0eb54472c9080b
|
data/lib/bup_bup_rb.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'bup_bup_rb/client'
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'faraday'
|
|
2
|
+
require 'singleton'
|
|
3
|
+
require 'bup_bup_rb/bupbup_error'
|
|
4
|
+
require 'bup_bup_rb/resources/device'
|
|
5
|
+
require 'bup_bup_rb/resources/notification'
|
|
6
|
+
|
|
7
|
+
module BupBupRB
|
|
8
|
+
class Client
|
|
9
|
+
include Singleton
|
|
10
|
+
|
|
11
|
+
attr_reader :config, :connection
|
|
12
|
+
|
|
13
|
+
def self.configure
|
|
14
|
+
yield(Configuration.instance) if block_given?
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def initialize
|
|
18
|
+
@config ||= Configuration.instance
|
|
19
|
+
|
|
20
|
+
@connection = ::Faraday.new(:url => @config.url) do |faraday|
|
|
21
|
+
faraday.request :url_encoded
|
|
22
|
+
faraday.response :logger
|
|
23
|
+
faraday.adapter Faraday.default_adapter
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.connection
|
|
28
|
+
instance.connection
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def access_token
|
|
32
|
+
BupBupRB::Resource::AccessToken
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def device
|
|
36
|
+
BupBupRB::Resource::Device
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def notification
|
|
40
|
+
BupBupRB::Resource::Notification
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class Configuration
|
|
44
|
+
include Singleton
|
|
45
|
+
|
|
46
|
+
attr_accessor :app_id, :app_secret, :url
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module BupBupRB
|
|
2
|
+
module Resource
|
|
3
|
+
class Device
|
|
4
|
+
def self.registration(uuid, platform, gcm_token)
|
|
5
|
+
timestamp = Time.now.getutc.to_i
|
|
6
|
+
signature = Digest::MD5.hexdigest("#{ timestamp }-#{ config.app_secret }")
|
|
7
|
+
|
|
8
|
+
response = connection.post do |req|
|
|
9
|
+
req.url '/api/devices'
|
|
10
|
+
req.body = '{ "uuid": uuid, "platform": platform, "gcm_token": gcm_token }'
|
|
11
|
+
req.headers['Content-Type'] = 'application/json'
|
|
12
|
+
req.headers['Authorization-Signature'] = signature
|
|
13
|
+
req.headers['Authorization-App-Id'] = config.app_id
|
|
14
|
+
req.headers['Authorization-Timestamp'] = timestamp.to_s
|
|
15
|
+
end
|
|
16
|
+
result = JSON.parse(response.body)
|
|
17
|
+
|
|
18
|
+
return result["result"] if result["status"]
|
|
19
|
+
raise BupbupError, result["message"]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.remove(key)
|
|
23
|
+
timestamp = Time.now.getutc.to_i
|
|
24
|
+
signature = Digest::MD5.hexdigest("#{ timestamp }-#{ config.app_secret }")
|
|
25
|
+
|
|
26
|
+
response = connection.delete do |req|
|
|
27
|
+
req.url "/api/devices/#{ key }"
|
|
28
|
+
req.headers['Content-Type'] = 'application/json'
|
|
29
|
+
req.headers['Authorization-Signature'] = signature
|
|
30
|
+
req.headers['Authorization-App-Id'] = config.app_id
|
|
31
|
+
req.headers['Authorization-Timestamp'] = timestamp.to_s
|
|
32
|
+
end
|
|
33
|
+
result = JSON.parse(response.body)
|
|
34
|
+
|
|
35
|
+
return result["result"] if result["status"]
|
|
36
|
+
raise BupbupError, result["message"]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def self.connection
|
|
42
|
+
BupBupRB::Client.instance.connection
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.config
|
|
46
|
+
BupBupRB::Client.instance.config
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module BupBupRB
|
|
2
|
+
module Resource
|
|
3
|
+
class Notification
|
|
4
|
+
def self.send(ids, message)
|
|
5
|
+
timestamp = Time.now.getutc.to_i
|
|
6
|
+
signature = Digest::MD5.hexdigest("#{ timestamp }-#{ config.app_secret }")
|
|
7
|
+
|
|
8
|
+
response = connection.post do |req|
|
|
9
|
+
req.url '/api/notifications'
|
|
10
|
+
req.body = '{ "device_ids": ids, "message": message }'
|
|
11
|
+
req.headers['Content-Type'] = 'application/json'
|
|
12
|
+
req.headers['Authorization-Signature'] = signature
|
|
13
|
+
req.headers['Authorization-App-Id'] = config.app_id
|
|
14
|
+
req.headers['Authorization-Timestamp'] = timestamp.to_s
|
|
15
|
+
end
|
|
16
|
+
result = JSON.parse(response.body)
|
|
17
|
+
|
|
18
|
+
return result["status"] if result["status"]
|
|
19
|
+
raise BupbupError, result["message"]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def self.connection
|
|
25
|
+
BupBupRB::Client.instance.connection
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.config
|
|
29
|
+
BupBupRB::Client.instance.config
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bup_bup_rb
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Cam Huynh
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-11-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: faraday
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.9'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.9'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '3.2'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '3.2'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: webmock
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: A simple hello world gem
|
|
56
|
+
email: jack.huang@dadadee.com
|
|
57
|
+
executables: []
|
|
58
|
+
extensions: []
|
|
59
|
+
extra_rdoc_files: []
|
|
60
|
+
files:
|
|
61
|
+
- lib/bup_bup_rb.rb
|
|
62
|
+
- lib/bup_bup_rb/bupbup_error.rb
|
|
63
|
+
- lib/bup_bup_rb/client.rb
|
|
64
|
+
- lib/bup_bup_rb/resources/device.rb
|
|
65
|
+
- lib/bup_bup_rb/resources/notification.rb
|
|
66
|
+
- lib/bup_bup_rb/version.rb
|
|
67
|
+
homepage: http://rubygems.org/gems/bup_bup_rb
|
|
68
|
+
licenses:
|
|
69
|
+
- MIT
|
|
70
|
+
metadata: {}
|
|
71
|
+
post_install_message:
|
|
72
|
+
rdoc_options: []
|
|
73
|
+
require_paths:
|
|
74
|
+
- lib
|
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0'
|
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
requirements: []
|
|
86
|
+
rubyforge_project:
|
|
87
|
+
rubygems_version: 2.2.2
|
|
88
|
+
signing_key:
|
|
89
|
+
specification_version: 4
|
|
90
|
+
summary: Bup Bup!
|
|
91
|
+
test_files: []
|