push_to_devices 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/README.md ADDED
@@ -0,0 +1,112 @@
1
+ Push to Devices Ruby Client Library
2
+ ------------------------------
3
+
4
+ [![Build
5
+ Status](https://secure.travis-ci.org/lloydmeta/push_to_devices_rb.png)](http://travis-ci.org/lloydmeta/push_to_devices_rb)
6
+
7
+ [![Code Climate](https://codeclimate.com/github/lloydmeta/push_to_devices_rb.png)](https://codeclimate.com/github/lloydmeta/push_to_devices_rb)
8
+
9
+ A Ruby client library for [Push to Devices server](https://github.com/lloydmeta/push_to_devices) to make it easier to register users, send notifications to users individually, and send a notification to a bunch of users.
10
+
11
+ Installation
12
+ ---------
13
+ $ gem install push_to_devices
14
+
15
+ or add to your ``Gemfile``
16
+
17
+ gem 'push_to_devices'
18
+
19
+ and install it with
20
+
21
+ $ bundle install
22
+
23
+ Basic Overview
24
+ ------------
25
+
26
+ 1. Deploy [Push to Devices server](https://github.com/lloydmeta/push_to_devices)
27
+ 2. Register a service in Push to Devices
28
+ 3. Take note of the Server and Mobile API credentials from the service
29
+ 4. Install this Gem
30
+ 5. Configure the gem according to the credentials in step 3.
31
+ 6. Interact with the Push to Devices service
32
+
33
+ Configuration
34
+ ------------
35
+
36
+ Simply use a config block.
37
+
38
+ The example below assumes a typical Rails-like setup (with a YAML file to hold your configuration of the Push to Devices server), but you can use any way you wish to hold your config.
39
+
40
+ ```Ruby
41
+ # Load the push_server.yml configuration file
42
+ push_server_config = YAML.load_file(Rails.root + 'config/push_server.yml')[rails_env].symbolize_keys
43
+
44
+ PushToDevices::API.configure do |config|
45
+ config.api_host = push_server_config[:api_host]
46
+ config.client_id = push_server_config[:client_id]
47
+ config.client_secret = push_server_config[:client_secret]
48
+ config.use_ssl = push_server_config[:use_ssl]
49
+ end
50
+ ```
51
+
52
+ Examples
53
+ --------
54
+
55
+ 1. Getting information about your Service as defined in the Push to Devices server
56
+
57
+ `PushToDevices::API.get_service_info`
58
+
59
+ 2. Register a user for push notifications
60
+
61
+ ```Ruby
62
+ data = {
63
+ unique_hash: "a unique hash of the user in your service",
64
+ apn_device_token: "an apple ios device token",
65
+ gcm_registration_id: "gcm_registration_id"
66
+ }
67
+ PushToDevices::API.register_user_for_push(data)
68
+ ```
69
+
70
+ 3. Send a notification to a user (Push to Devices server takes care of sending to all the user's devices)
71
+
72
+ ```Ruby
73
+ unique_hash = "jkl4h6l4j36h3lj6ghjgk2jh"
74
+ notification_data = {
75
+ ios_specific_fields: {alert: "Hello!", badge: 3},
76
+ android_specific_fields: {title: "Android notification", text: "Hello Android user!"}
77
+ }
78
+ PushToDevices::API.post_notification_to_user(unique_hash: unique_hash, notification_data: notification_data)
79
+ ```
80
+
81
+ 4. Send a notification to a group of users
82
+
83
+ ```Ruby
84
+ unique_hashes = ["h1k43jgh14g6hl34j1g6", "1bjhl6b134hj6gl41hj6", ...]
85
+ notification_data = {
86
+ ios_specific_fields: {alert: "Hello!", badge: 3},
87
+ android_specific_fields: {title: "Android notification", text: "Hello Android user!"}
88
+ }
89
+ PushToDevices::API.post_notification_to_users(unique_hashes: unique_hashes, notification_data: notification_data)
90
+ ```
91
+
92
+ ## License
93
+
94
+ Copyright (c) 2013 by Lloyd Chan
95
+
96
+ Permission is hereby granted, free of charge, to any person obtaining a
97
+ copy of this software and associated documentation files (the
98
+ "Software"), to deal in the Software without restriction, including
99
+ without limitation the rights to use, copy, modify, merge, publish,
100
+ distribute, and to permit persons to whom the Software is furnished to do so, subject to
101
+ the following conditions:
102
+
103
+ The above copyright notice and this permission notice shall be included
104
+ in all copies or substantial portions of the Software.
105
+
106
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
107
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
108
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
109
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
110
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
111
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
112
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -60,14 +60,7 @@ module PushToDevices
60
60
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
61
61
  end
62
62
 
63
- if params.empty?
64
- uri="/"+endpoint
65
- else
66
- query_string = params.map {|k, v|
67
- "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
68
- }.join("&")
69
- uri = "/"+endpoint+"?"+query_string
70
- end
63
+ uri = self.generate_uri_from_params(endpoint, params)
71
64
 
72
65
  # Set up the request
73
66
  request = Net::HTTP::Get.new(uri)
@@ -116,6 +109,17 @@ module PushToDevices
116
109
  self.handle_response(response)
117
110
  end
118
111
 
112
+ def self.generate_uri_from_params(endpoint, params)
113
+ if params.empty?
114
+ "/#{endpoint}"
115
+ else
116
+ query_string = params.map {|k, v|
117
+ "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
118
+ }.join("&")
119
+ "/#{endpoint}?#{query_string}"
120
+ end
121
+ end
122
+
119
123
  def self.generate_client_credentials
120
124
  timestamp_s = Time.now.to_i.to_s
121
125
  {
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = %q{push_to_devices}
3
- gem.version = "0.0.8"
3
+ gem.version = "0.0.9"
4
4
  gem.date = %q{2013-02-15}
5
5
  gem.authors = ["Lloyd Meta"]
6
6
  gem.email = ["lloydmeta@gmail.com"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: push_to_devices
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -116,7 +116,9 @@ extra_rdoc_files: []
116
116
  files:
117
117
  - .gitignore
118
118
  - .rspec
119
+ - .travis.yml
119
120
  - Gemfile
121
+ - README.md
120
122
  - Rakefile
121
123
  - lib/push_to_devices.rb
122
124
  - push_to_devices.gemspec