batch_push_notification 0.0.5

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3c42474a440ab41b0d48998a444ca7ddebfe69d
4
+ data.tar.gz: c8225b3b9511d8db02a77a5934dc2f67114447e2
5
+ SHA512:
6
+ metadata.gz: e19b5a2570f2caf60448df8fcaf2d2f619b28be5cb2d9bd66e0190eede2a2197810a03d7e1048692ad97a888a6592cd697996f67de229c8c8c8ddc8ce69b710b
7
+ data.tar.gz: 47d1053b41bdf2400fe03ec510b3b0622add728a4ed56c6fafdd6756ea2faf4fa839b1fc1056dd216360de12ee3eb10db3bff4e1d305d0882cee0346dcffed6f
@@ -0,0 +1,9 @@
1
+ module BatchPushNotification
2
+ autoload :Configurable, 'batch_push_notification/configurable'
3
+ autoload :Client, 'batch_push_notification/client'
4
+ autoload :Notification, 'batch_push_notification/notification'
5
+
6
+ class << self
7
+ include BatchPushNotification::Configurable
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ module BatchPushNotification
2
+ class Notification
3
+ def initialize(args = {})
4
+ @group_id = args[:group_id]
5
+ @tokens = args[:tokens]
6
+ @custom_ids = args[:custom_ids]
7
+ @title = args[:title]
8
+ @body = args[:body]
9
+ @custom_payload = args[:custom_payload]
10
+ end
11
+
12
+ def payload
13
+ {
14
+ "group_id": @group_id,
15
+ "recipients": {
16
+ "tokens": @tokens,
17
+ "custom_ids": @custom_ids
18
+ },
19
+ "message": {
20
+ "title": @title,
21
+ "body": @body
22
+ },
23
+ "custom_payload": @custom_payload.to_json.to_s, # the API expects a string instead of a JSON object
24
+ sandbox: BatchPushNotification.sandbox
25
+ }.to_json
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ require 'json'
2
+ require 'faraday'
3
+
4
+ module BatchPushNotification
5
+ class Client
6
+ def initialize
7
+ # fail if the required params are not set:
8
+ raise(StandardError, 'Configuration is missing') unless BatchPushNotification.endpoint && BatchPushNotification.api_key && BatchPushNotification.rest_api_key && !BatchPushNotification.sandbox.nil?
9
+ end
10
+
11
+ def send_notification(notification)
12
+ response = connection.post send_url, notification.payload
13
+ return JSON.parse(response.body)
14
+ end
15
+
16
+ def connection
17
+ return Faraday.new(:url => BatchPushNotification.endpoint) do |faraday|
18
+ faraday.response :logger # log requests to STDOUT
19
+ faraday.headers['Content-Type'] = 'application/json'
20
+ faraday.headers['X-Authorization'] = BatchPushNotification.rest_api_key
21
+
22
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
23
+ end
24
+ end
25
+
26
+ def send_url
27
+ BatchPushNotification.api_key + '/transactional/send'
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ # Based on https://github.com/sethvargo/chef-api/blob/master/lib/chef-api/configurable.rb
2
+ module BatchPushNotification
3
+ #
4
+ # Use this class to configure the Client
5
+ #
6
+ module Configurable
7
+ class << self
8
+
9
+ def keys
10
+ @keys = [
11
+ :endpoint,
12
+ :api_key,
13
+ :rest_api_key,
14
+ :sandbox
15
+ ]
16
+ end
17
+ end
18
+
19
+ BatchPushNotification::Configurable.keys.each do |key|
20
+ attr_accessor key
21
+ end
22
+
23
+ #
24
+ # Configure the client like this:
25
+ #
26
+ # BatchPushNotification.configure do |config|
27
+ # config.endpoint = "https://api.batch.com/1.0/"
28
+ # end
29
+ #
30
+ def configure
31
+ yield self
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe BatchPushNotification::Client do
4
+
5
+ let(:endpoint) {"https://api.batch.com/1.0/"}
6
+ let(:api_key) {""}
7
+ let(:rest_api_key) {""}
8
+
9
+ # notification
10
+ let(:group_id) {'test'}
11
+ let(:tokens) { [""] }
12
+
13
+ let(:title) { 'Title' }
14
+ let(:body) { 'Body2' }
15
+ let(:sandbox) { false }
16
+
17
+ let(:custom_payload) { {:poll_id => 1} }
18
+ let(:notification) { BatchPushNotification::Notification.new({group_id: group_id, tokens: tokens, title: title, body: body, custom_payload: custom_payload}) }
19
+
20
+ #def initialize(group_id, tokens = [], custom_ids = [], title, body, custom_payload)
21
+
22
+ before {
23
+ BatchPushNotification.configure do |config|
24
+ config.endpoint = endpoint
25
+ config.api_key = api_key
26
+ config.rest_api_key = rest_api_key
27
+ config.sandbox = sandbox
28
+ end
29
+ }
30
+
31
+
32
+ it "can send a notification" do
33
+ client = BatchPushNotification::Client.new
34
+ response = client.send_notification(notification)
35
+
36
+ expect(response['token']).to_not be_nil
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe BatchPushNotification do
4
+
5
+ let(:endpoint) {"https://api.batch.com/1.0/"}
6
+ let(:api_key) {""}
7
+ let(:rest_api_key) {""}
8
+
9
+
10
+ it "can be configured using a block" do
11
+
12
+ BatchPushNotification.configure do |config|
13
+ config.endpoint = endpoint
14
+ config.api_key = api_key
15
+ config.rest_api_key = rest_api_key
16
+ end
17
+
18
+ expect(BatchPushNotification.endpoint).to eq(endpoint)
19
+ expect(BatchPushNotification.api_key).to eq(api_key)
20
+ expect(BatchPushNotification.rest_api_key).to eq(rest_api_key)
21
+ end
22
+ end
@@ -0,0 +1,81 @@
1
+ require 'batch_push_notification'
2
+
3
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
4
+ RSpec.configure do |config|
5
+ # rspec-expectations config goes here. You can use an alternate
6
+ # assertion/expectation library such as wrong or the stdlib/minitest
7
+ # assertions if you prefer.
8
+ config.expect_with :rspec do |expectations|
9
+ # This option will default to `true` in RSpec 4. It makes the `description`
10
+ # and `failure_message` of custom matchers include text for helper methods
11
+ # defined using `chain`, e.g.:
12
+ # be_bigger_than(2).and_smaller_than(4).description
13
+ # # => "be bigger than 2 and smaller than 4"
14
+ # ...rather than:
15
+ # # => "be bigger than 2"
16
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
17
+ end
18
+
19
+ # rspec-mocks config goes here. You can use an alternate test double
20
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
21
+ config.mock_with :rspec do |mocks|
22
+ # Prevents you from mocking or stubbing a method that does not exist on
23
+ # a real object. This is generally recommended, and will default to
24
+ # `true` in RSpec 4.
25
+ mocks.verify_partial_doubles = true
26
+ end
27
+
28
+ # The settings below are suggested to provide a good initial experience
29
+ # with RSpec, but feel free to customize to your heart's content.
30
+ =begin
31
+ # These two settings work together to allow you to limit a spec run
32
+ # to individual examples or groups you care about by tagging them with
33
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
34
+ # get run.
35
+ config.filter_run :focus
36
+ config.run_all_when_everything_filtered = true
37
+
38
+ # Allows RSpec to persist some state between runs in order to support
39
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
40
+ # you configure your source control system to ignore this file.
41
+ config.example_status_persistence_file_path = "spec/examples.txt"
42
+
43
+ # Limits the available syntax to the non-monkey patched syntax that is
44
+ # recommended. For more details, see:
45
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
46
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
47
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
48
+ config.disable_monkey_patching!
49
+
50
+ # This setting enables warnings. It's recommended, but in some cases may
51
+ # be too noisy due to issues in dependencies.
52
+ config.warnings = true
53
+
54
+ # Many RSpec users commonly either run the entire suite or an individual
55
+ # file, and it's useful to allow more verbose output when running an
56
+ # individual spec file.
57
+ if config.files_to_run.one?
58
+ # Use the documentation formatter for detailed output,
59
+ # unless a formatter has already been configured
60
+ # (e.g. via a command-line flag).
61
+ config.default_formatter = 'doc'
62
+ end
63
+
64
+ # Print the 10 slowest examples and example groups at the
65
+ # end of the spec run, to help surface which specs are running
66
+ # particularly slow.
67
+ config.profile_examples = 10
68
+
69
+ # Run specs in random order to surface order dependencies. If you find an
70
+ # order dependency and want to debug it, you can fix the order by providing
71
+ # the seed, which is printed after each run.
72
+ # --seed 1234
73
+ config.order = :random
74
+
75
+ # Seed global randomization in this process using the `--seed` CLI option.
76
+ # Setting this allows you to use `--seed` to deterministically reproduce
77
+ # test failures related to randomization by passing the same `--seed` value
78
+ # as the one that triggered the failure.
79
+ Kernel.srand config.seed
80
+ =end
81
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: batch_push_notification
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Nicholas Wittstruck
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-18 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A client for the batch.com Push Notification API
28
+ email: n.wittstruck@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/batch_push_notification.rb
34
+ - lib/batch_push_notification/Notification.rb
35
+ - lib/batch_push_notification/client.rb
36
+ - lib/batch_push_notification/configurable.rb
37
+ - spec/batch_push_notification/client_spec.rb
38
+ - spec/batch_push_notification/configurable_spec.rb
39
+ - spec/spec_helper.rb
40
+ homepage: https://github.com/nwittstruck/batch
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.4.8
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Batch
64
+ test_files:
65
+ - spec/batch_push_notification/client_spec.rb
66
+ - spec/batch_push_notification/configurable_spec.rb
67
+ - spec/spec_helper.rb