njiuko-pwush 0.3.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 60a9a2ea8e0265c8f275ca51a36f9b1517eaedf47862d70b46743a019af1bea9
4
+ data.tar.gz: 811e46470701ee7345311d173f2a4896fd2edb2f8b6d8044404aadbbfd5cab66
5
+ SHA512:
6
+ metadata.gz: 1235a03026893de2de7e4c9c514075d131eb80ec5de457f9a051418ee8aff03afbe0830574d445a670de12d93e2e099390277d0d659a165bc2f765e932ddca5e
7
+ data.tar.gz: 6a7cc440e151f4276f9e53e4b0118702cc73829c1a7df6e1e68e30c122099412a0f36c19b5e67ebef041f45abbff6c462ac9ab5f9070708d275626748f8cb4a8
@@ -0,0 +1,64 @@
1
+ version: 2.0
2
+ defaults: &default_job
3
+ working_directory: ~/repo
4
+
5
+ docker:
6
+ - image: circleci/ruby:2.4-node-browsers
7
+
8
+ steps:
9
+ - checkout
10
+
11
+ # - type: cache-restore
12
+ # name: Restore bundle cache
13
+ # key: pwush-{{ checksum "Gemfile.lock" }}
14
+
15
+ - run:
16
+ name: install dependencies
17
+ command: |
18
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
19
+
20
+ # - type: cache-save
21
+ # name: Store bundle cache
22
+ # key: pwush-{{ checksum "Gemfile.lock" }}
23
+ # paths:
24
+ # - vendor/bundle
25
+
26
+ - run:
27
+ name: Download cc-test-reporter
28
+ command: |
29
+ mkdir -p tmp/
30
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
31
+ chmod +x ./tmp/cc-test-reporter
32
+
33
+ - run:
34
+ name: Run tests
35
+ command: |
36
+ bundle exec rake
37
+ ./tmp/cc-test-reporter format-coverage -t simplecov -o tmp/codeclimate.json
38
+
39
+ - run:
40
+ name: Upload coverage results to Code Climate
41
+ command: |
42
+ ./tmp/cc-test-reporter upload-coverage -i tmp/codeclimate.json -r ce337e25b76b0c3048abfdb2d5aa6d3e87cc8540d90f0029ef7416683814732e
43
+
44
+ jobs:
45
+ ruby-2.4:
46
+ <<: *default_job
47
+ docker:
48
+ - image: circleci/ruby:2.4-node-browsers
49
+ ruby-2.5:
50
+ <<: *default_job
51
+ docker:
52
+ - image: circleci/ruby:2.5-node-browsers
53
+ ruby-2.6:
54
+ <<: *default_job
55
+ docker:
56
+ - image: circleci/ruby:2.6-node-browsers
57
+
58
+ workflows:
59
+ version: 2
60
+ multiple-rubies:
61
+ jobs:
62
+ - ruby-2.4
63
+ - ruby-2.5
64
+ - ruby-2.6
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # Change Log
2
+
3
+ ## [0.3.0](https://github.com/iarie/pwush/tree/HEAD)
4
+ - Update Dry-Struct runtime dependecy to 1.0
5
+ - Drop ruby 2.3 support
6
+
7
+ ## [0.2.0](https://github.com/iarie/pwush/tree/HEAD)
8
+
9
+ **Added:**
10
+ - Introduce devices api [\#4](https://github.com/iarie/pwush/pull/4) ([iarie](https://github.com/iarie))
11
+
12
+ ## [0.1.2](https://github.com/iarie/pwush/tree/HEAD)
13
+
14
+ **Changed:**
15
+ - Update dry-rb gems [\#3](https://github.com/iarie/pwush/pull/3)
16
+
17
+ ## [0.1.1](https://github.com/iarie/pwush/tree/HEAD)
18
+
19
+ **Added:**
20
+ - timeout config options added [\#1](https://github.com/iarie/pwush/pull/1) ([achernik](https://github.com/achernik))
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at litvinov@applicot.ru. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in pw.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Yaroslav Litvinov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ [![CircleCI](https://circleci.com/gh/iarie/pwush/tree/master.svg?style=shield)](https://circleci.com/gh/iarie/pwush/tree/master)
2
+ [![Gem Version](https://badge.fury.io/rb/pwush.svg)](https://badge.fury.io/rb/pwush)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/d1887381dee84e26e860/maintainability)](https://codeclimate.com/github/iarie/pwush/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/d1887381dee84e26e860/test_coverage)](https://codeclimate.com/github/iarie/pwush/test_coverage)
5
+
6
+ # Pwush
7
+
8
+ Pwush is a remote api toolkit for [Pushwoosh](https://www.pushwoosh.com/v1.0/reference)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'pwush', '~> 0.3.0'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install pwush
25
+
26
+ ## Basic Usage
27
+
28
+ ### Setup pwush client
29
+ ```ruby
30
+ MyPW = Pwush.new(auth: 'AUTH_KEY', app: 'APP_CODE', timeout: { connect: 5, read: 10, write: 2 })
31
+ ```
32
+ ### Push message
33
+ ```ruby
34
+ MyPW.create_message(content: 'Hello, there!')
35
+ ```
36
+ ### Using built-in struct
37
+ ```ruby
38
+ first_message = Pwush::Message.new(
39
+ content: { en: 'Hello' },
40
+ send_date: '2018-04-06 23:00',
41
+ timezone: 'Europe/London',
42
+ devices: ['token1', 'token2'],
43
+ ios_title: 'This is the test message',
44
+ ios_subtitle: 'subtitle!'
45
+ )
46
+
47
+ second_message = Pwush::Message.new(
48
+ content: { es: 'Hola' },
49
+ send_date: '2018-04-06 23:00',
50
+ timezone: 'Europe/Madrid',
51
+ devices: ['token3', 'token4'],
52
+ android_banner: 'This is the test message',
53
+ android_gcm_ttl: 3600
54
+ )
55
+
56
+ MyPW.push(first_message, second_message)
57
+ ```
58
+
59
+ ### Result
60
+ The result is `dry-monads` Success or Failure, [read about it](http://dry-rb.org/gems/dry-monads/result/)
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/iarie/pwush. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
69
+
70
+ ## Code of Conduct
71
+
72
+ Everyone interacting in the PwRb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/iarie/pwush/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'pwush'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require 'pry'
11
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ module Pwush
2
+ module Api
3
+ module Applications
4
+ def applications
5
+ post(:getApplications)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,41 @@
1
+ module Pwush
2
+ module Api
3
+ module Devices
4
+ def register_device(params)
5
+ post(:registerDevice, params)
6
+ end
7
+
8
+ def unregister_device(hwid)
9
+ post(:unregisterDevice, hwid: hwid)
10
+ end
11
+
12
+ def create_test_device(params)
13
+ post(:createTestDevice, params)
14
+ end
15
+
16
+ def list_test_devices
17
+ post(:listTestDevices)
18
+ end
19
+
20
+ def set_badge(hwid, badge)
21
+ post(:setBadge, hwid: hwid, badge: badge)
22
+ end
23
+
24
+ def application_open(hwid)
25
+ post(:applicationOpen, hwid: hwid)
26
+ end
27
+
28
+ def push_stat(hwid, hash_tag = nil)
29
+ post(:pushStat, hwid: hwid, hash: hash_tag)
30
+ end
31
+
32
+ def message_delivery_event(hwid, hash_tag = nil)
33
+ post(:messageDeliveryEvent, hwid: hwid, hash: hash_tag)
34
+ end
35
+
36
+ def set_purchase(hwid, params = {})
37
+ post(:setPurchase, params.merge(hwid: hwid))
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,30 @@
1
+ module Pwush
2
+ module Api
3
+ module Messages
4
+ def create_message(*messages)
5
+ post(:createMessage, notifications: messages.flatten)
6
+ end
7
+ alias push create_message
8
+
9
+ def delete_message(message_code)
10
+ post(:deleteMessage, message: message_code)
11
+ end
12
+
13
+ def message_details(message)
14
+ post(:getMessageDetails, message: message)
15
+ end
16
+
17
+ def message_stats(message)
18
+ post(:getMsgStats, message: message)
19
+ end
20
+
21
+ def results(request_id)
22
+ post(:getResults, request_id: request_id)
23
+ end
24
+
25
+ def preset(preset_code)
26
+ post(:getPreset, preset_code: preset_code)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ require 'http'
2
+
3
+ require 'pwush/api/messages'
4
+ require 'pwush/api/devices'
5
+ require 'pwush/api/applications'
6
+
7
+ module Pwush
8
+ class Client
9
+ include Api::Messages
10
+ include Api::Devices
11
+ include Api::Applications
12
+
13
+ def initialize(options)
14
+ @config = Config.new(options)
15
+ end
16
+
17
+ private
18
+
19
+ def get(action, payload = nil)
20
+ perform_request(:get, action, payload)
21
+ end
22
+
23
+ def post(action, payload = nil)
24
+ perform_request(:post, action, payload)
25
+ end
26
+
27
+ def perform_request(verb, action, payload)
28
+ Response.wrap { raw_request(verb, action, payload) }
29
+ end
30
+
31
+ def raw_request(verb, action, payload)
32
+ request = build_request(payload)
33
+ url = url(action)
34
+
35
+ @config.logger.info(
36
+ "Pushwoosh #{verb.upcase} #{url} BODY #{request.body.to_json}"
37
+ )
38
+
39
+ HTTP.timeout(@config.timeout).request(verb, url, json: request.body)
40
+ end
41
+
42
+ def build_request(payload = nil)
43
+ Request.new(auth: @config.auth, app: @config.app, payload: payload)
44
+ end
45
+
46
+ def url(action)
47
+ [@config.url, action].join('/')
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,30 @@
1
+ require 'logger'
2
+
3
+ module Pwush
4
+ MissingAuthToken = Class.new(StandardError)
5
+ MissingAppToken = Class.new(StandardError)
6
+
7
+ class Config
8
+ URL = 'https://cp.pushwoosh.com/json/1.3'.freeze
9
+
10
+ def initialize(options = {})
11
+ @url = options[:url] || URL
12
+ @auth = options[:auth] || auth_missing
13
+ @app = options[:app] || app_missing
14
+ @timeout = options[:timeout] || { write: 2, connect: 5, read: 10 }
15
+ @logger = options[:logger] || Logger.new(STDOUT)
16
+ end
17
+
18
+ attr_accessor :auth, :url, :app, :timeout, :logger
19
+
20
+ private
21
+
22
+ def auth_missing
23
+ raise(MissingAuthToken, 'please provide :auth argument')
24
+ end
25
+
26
+ def app_missing
27
+ raise(MissingAppToken, 'please provide :app argument')
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,312 @@
1
+ module Pwush
2
+ class Message < Dry::Struct
3
+ # transform_types do |type|
4
+ # type.constructor { |value| value.nil? ? Undefined : value }
5
+ # end
6
+ # https://www.pushwoosh.com/v1.0/reference#createmessage
7
+
8
+ # YYYY-MM-DD HH:mm OR 'now'
9
+ attribute :send_date, Types::Strict::String.default('now'.freeze)
10
+
11
+ attribute :ignore_user_timezone, Types::Strict::Bool.default(true)
12
+
13
+ # "timezone":"America/New_York", optional, if ignored UTC-0 is default in "send_date".
14
+ # See http://php.net/manual/timezones.php for supported timezones
15
+ attribute? :timezone, Types::Strict::String
16
+
17
+ # "campaign":"CAMPAIGN_CODE", optional.
18
+ # Campaign code to which you want to assign this push message
19
+ attribute? :campaign, Types::Strict::String
20
+
21
+ # "content":{
22
+ # "en":"English",
23
+ # "ru":"Русский",
24
+ # "de":"Deutsch"
25
+ # },
26
+ attribute :content, Types::Strict::String | Types::Hash
27
+
28
+ # "page_id": 39, optional. HTML Pages. integer
29
+ attribute? :page_id, Types::Strict::Integer
30
+
31
+ # "rich_page_id": 42, optional. Rich Pages. integer
32
+ attribute? :rich_page_id, Types::Strict::Integer
33
+
34
+ # "rich_media": "XXXX-XXXX", optional. Rich Media code. string
35
+ attribute? :rich_media, Types::Strict::String
36
+
37
+ # "remote_page" : "http://myremoteurl.com",
38
+ # Remote Rich HTML Page URL. <scheme>://<authority>
39
+ attribute? :remote_page, Types::Strict::String
40
+
41
+ # "link": "http://google.com", optional, string.
42
+ # For deeplinks add "minimize_link":0
43
+ attribute? :link, Types::Strict::String
44
+
45
+ # "minimize_link": 0, optional.
46
+ # False or 0 - do not minimize, 1 - Google, 2 - bitly. Default = 1
47
+ attribute? :minimize_link, Types::Strict::Integer.constrained(included_in: 0..2)
48
+
49
+ # "data": {"key":"value"}, JSON string or JSON object,
50
+ # will be passed as "u" parameter in the payload (converted to JSON string)
51
+ attribute? :data, Types::Strict::String | Types::Hash
52
+
53
+ # 1 - iOS; 2 - BB; 3 - Android; 5 - Windows Phone; 7 - OS X; 8 - Windows 8;
54
+ # 9 - Amazon; 10 - Safari; 11 - Chrome; 12 - Firefox;
55
+ # ignored if "devices" < 10
56
+ Platforms = Types::Strict::Integer.enum(1, 2, 3, 5, 7, 8, 9, 10, 11, 12)
57
+ attribute? :platforms, Types::Strict::Array.of(Platforms)
58
+
59
+ # "preset":"Q1A2Z-6X8SW", Push Preset Code from your Control Panel
60
+ attribute? :preset, Types::Strict::String
61
+
62
+ # "send_rate": 100, throttling. Valid values are from 100 to 1000 pushes/second.
63
+ attribute? :send_rate, Types::Strict::Integer.constrained(included_in: 100..1000)
64
+
65
+ # Optional. Specify tokens or hwids to send targeted push notifications.
66
+ # Not more than 1000 tokens/hwids in an array.
67
+ # If set, the message will only be sent to the devices on the list.
68
+ # Ignored if the Applications Group is used. iOS push tokens can only be lower case.
69
+ attribute? :devices, Types::Strict::Array.of(Types::Strict::String)
70
+
71
+ # "users":["user_3078a"], optional.
72
+ # If set, message will only be delivered to the specified users Id's
73
+ # (specified via /registerUser call).
74
+ # If specified together with devices parameter, the latter will be ignored.
75
+ attribute? :users, Types::Strict::Array.of(Types::Strict::String)
76
+
77
+ # "filter": "FILTER_NAME", optional.
78
+ attribute? :filter, Types::Strict::String
79
+
80
+ # optional, placeholders for dynamic content instead of device tags
81
+ # "dynamic_content_placeholders" :{
82
+ # "firstname":"John",
83
+ # "lastname":"Doe"
84
+ # },
85
+ attribute? :dynamic_content_placeholders, Types::Hash
86
+
87
+ # "conditions": [TAG_CONDITION1, TAG_CONDITION2, ..., TAG_CONDITIONN],
88
+ # Optional.
89
+ attribute? :conditions, Types::Strict::Array.of(Types::Strict::String)
90
+
91
+ # iOS related
92
+
93
+ # "ios_badges": 5, optional, integer.
94
+ # iOS application badge number.
95
+ # Use "+n" or "-n" to increment/decrement the badge value by n
96
+ attribute? :ios_badges, Types::Strict::Integer
97
+
98
+ # "ios_sound": "sound file.wav", optional.
99
+ # Sound file name in the main bundle of application.
100
+ # If left empty, the device will produce no sound upon receiving a push
101
+ attribute? :ios_sound, Types::Strict::String
102
+
103
+ # "ios_ttl": 3600, optional.
104
+ # Time to live parameter - maximum message lifespan in seconds
105
+ attribute? :ios_ttl, Types::Strict::Integer
106
+
107
+ # "ios_silent": 1, optional.
108
+ # Enable silent notifications (ignore "sound" and "content")
109
+ attribute? :ios_silent, Types::Strict::Integer.constrained(included_in: 0..1)
110
+
111
+ # iOS8 category ID from Pushwoosh
112
+ attribute? :ios_category_id, Types::Strict::Integer
113
+
114
+ # Optional - root level parameters to the aps dictionary
115
+ # "ios_root_params" : {
116
+ # "aps":{
117
+ # "content-available": "1",
118
+ # "mutable-content":1 //required for iOS 10 Media attachments
119
+ # },
120
+ # "attachment":"YOUR_ATTACHMENT_URL", // iOS 10 media attachment URL
121
+ # "data": << User supplied data, max of 4KB>>
122
+ # },
123
+ attribute? :ios_root_params, Types::Hash
124
+
125
+ # "apns_trim_content":1, optional. (0|1)
126
+ # Trims the exceeding content strings with ellipsis
127
+ attribute? :apns_trim_content, Types::Strict::Integer.constrained(included_in: 0..1)
128
+
129
+ # "ios_title":"Title", optional. Add Title for push notification
130
+ attribute? :ios_title, Types::Strict::String
131
+
132
+ # "ios_subtitle" : "SubTitle", //Optional. Added sub-title for push notification
133
+ attribute? :ios_subtitle, Types::Strict::String
134
+
135
+ # Android related
136
+
137
+ # "android_root_params": {"key": "value"}
138
+ # custom key-value object. root level parameters for the android payload recipients
139
+ attribute? :android_root_params, Types::Hash
140
+
141
+ # "android_sound" : "soundfile", optional. No file extension.
142
+ # If left empty, the device will produce no sound upon receiving a push
143
+ attribute? :android_sound, Types::Strict::String
144
+
145
+ # "android_header":"header", optional. Android notification header
146
+ attribute? :android_header, Types::Strict::String
147
+
148
+ # "android_icon": "icon",
149
+ attribute? :android_icon, Types::Strict::String
150
+
151
+ # "android_custom_icon": "http://example.com/image.png", optional.
152
+ # Full path URL to the image file
153
+ attribute? :android_custom_icon, Types::Strict::String
154
+
155
+ # "android_banner": "http://example.com/banner.png", optional.
156
+ # Full path URL to the image file
157
+ attribute? :android_banner, Types::Strict::String
158
+
159
+ # "android_badges": 5, optional, integer.
160
+ # Android application icon badge number.
161
+ # Use "+n" or "-n" to increment/decrement the badge value by n
162
+ attribute? :android_badges, Types::Strict::Integer
163
+
164
+ # "android_gcm_ttl": 3600, optional.
165
+ # Time to live parameter - maximum message lifespan in seconds
166
+ attribute? :android_gcm_ttl, Types::Strict::Integer
167
+
168
+ # "android_vibration": 0, Android force-vibration for high-priority pushes, boolean
169
+ attribute? :android_vibration, Types::Strict::Bool
170
+
171
+ # "android_led":"#rrggbb", LED hex color, device will do its best approximation
172
+ attribute? :android_led, Types::Strict::String
173
+
174
+ # "android_priority":-1, priority of the push in the Android push drawer.
175
+ # Valid values are -2, -1, 0, 1 and 2
176
+ attribute? :android_priority, Types::Strict::Integer.constrained(included_in: -2..2)
177
+
178
+ # "android_ibc":"#RRGGBB", icon background color on Lollipop,
179
+ # #RRGGBB, #AARRGGBB, "red", "black", "yellow", etc.
180
+ attribute? :android_ibc, Types::Strict::String
181
+
182
+ # "android_silent": 1, optional. 0 or 1
183
+ # Enable silent notificaiton (ignore sound and content)
184
+ attribute? :android_silent, Types::Strict::Integer.constrained(included_in: 0..1)
185
+
186
+ # Amazon related
187
+
188
+ # "adm_root_params": {"key": "value"}, // custom key-value object
189
+ attribute? :adm_root_params, Types::Hash
190
+ # "adm_sound": "push.mp3",
191
+ attribute? :adm_sound, Types::Strict::String
192
+ # "adm_header": "Header",
193
+ attribute? :adm_header, Types::Strict::String
194
+ # "adm_icon": "icon",
195
+ attribute? :adm_icon, Types::Strict::String
196
+ # "adm_custom_icon": "http://example.com/image.png",
197
+ attribute? :adm_custom_icon, Types::Strict::String
198
+ # "adm_banner": "http://example.com/banner.png",
199
+ attribute? :adm_banner, Types::Strict::String
200
+ # "adm_ttl": 3600, optional. Time to live parameter - the maximum message lifespan in seconds
201
+ attribute? :adm_ttl, Types::Strict::Integer
202
+ # "adm_priority":-1, priority of the push in Amazon push drawer, valid values are -2, -1, 0, 1 and 2
203
+ attribute? :adm_priority, Types::Strict::Integer.constrained(included_in: -2..2)
204
+
205
+ # Windows Phone related
206
+
207
+ # Windows Phone notification type. 'Tile' or 'Toast'. Raw notifications are not supported. 'Tile' if default
208
+ attribute? :wp_type, Types::Strict::String
209
+ # tile image
210
+ attribute? :wp_background, Types::Strict::String
211
+ # back tile image
212
+ attribute? :wp_backbackground, Types::Strict::String
213
+ # back tile title
214
+ attribute? :wp_backtitle, Types::Strict::String
215
+ # back tile content
216
+ attribute? :wp_backcontent, Types::Strict::String
217
+ # Badge for Windows Phone notification
218
+ attribute? :wp_count, Types::Strict::Integer
219
+
220
+ # BlackBerry related
221
+
222
+ # BlackBerry header, applicable to BB10 Series devices
223
+ attribute? :blackberry_header, Types::Strict::String
224
+
225
+ # Mac OS X related
226
+
227
+ # "mac_badges": 3,
228
+ attribute? :mac_badges, Types::Strict::Integer
229
+ # "mac_sound": "sound.caf",
230
+ attribute? :mac_sound, Types::Strict::String
231
+ # "mac_root_params": {"content-available":1},
232
+ attribute? :mac_root_params, Types::Hash
233
+ # Time to live parameter — maximum message lifespan in seconds
234
+ attribute? :mac_ttl, Types::Strict::Integer
235
+
236
+ # WNS related
237
+
238
+ # Content (XML or raw) of notification encoded in MIME's base64 in form of Object( language1: 'content1', language2: 'content2' ) OR String
239
+ # "en": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9ImF2YWlsYWJsZSIvPg==",
240
+ # "de": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9Im5ld01lc3NhZ2UiLz4="
241
+ # },
242
+ attribute? :wns_content, Types::Hash
243
+ # 'Tile' | 'Toast' | 'Badge' | 'Raw'
244
+ attribute? :wns_type, Types::Strict::String
245
+ # optional. Used in Tile replacement policy. An alphanumeric string of no more than 16 characters.
246
+ attribute? :wns_tag, Types::Strict::String
247
+ # optional. (1|0) Translates into X-WNS-Cache-Policy value
248
+ attribute? :wns_cache, Types::Strict::Integer
249
+ # optional. Expiration time for notification in seconds
250
+ attribute? :wns_ttl, Types::Strict::Integer
251
+
252
+ # Safari related
253
+
254
+ # obligatory, title of the notification
255
+ attribute? :safari_title, Types::Strict::String
256
+
257
+ # "safari_action": "Click here", // optional
258
+ attribute? :safari_action, Types::Strict::String
259
+
260
+ # "safari_url_args": ["firstArgument", "secondArgument"],
261
+ # Obligatory, but the value may be empty
262
+ attribute? :safari_url_args, Types::Strict::Array.of(Types::Strict::String)
263
+
264
+ # Optional. Time to live parameter - the maximum lifespan of a message in seconds
265
+ attribute? :safari_ttl, Types::Strict::Integer.constrained(min_size: 0)
266
+
267
+ # Chrome related
268
+
269
+ # You can specify the header of the message in this parameter
270
+ attribute? :chrome_title, Types::Strict::String
271
+
272
+ # "chrome_icon":"", full path URL to the icon or extension resources file path
273
+ attribute? :chrome_icon, Types::Strict::String
274
+
275
+ # Time to live parameter - maximum message lifespan in seconds
276
+ attribute? :chrome_gcm_ttl, Types::Strict::Integer
277
+
278
+ # optional, changes chrome push display time.
279
+ # Set to 0 to display push until user interacts with it
280
+ attribute? :chrome_duration, Types::Strict::Integer
281
+
282
+ # optional, URL to large image.
283
+ attribute? :chrome_image, Types::Strict::String
284
+
285
+ attribute? :chrome_button_text1, Types::Strict::String
286
+
287
+ # ignored if chrome_button_text1 is not set
288
+ attribute? :chrome_button_url1, Types::Strict::String
289
+
290
+ attribute? :chrome_button_text2, Types::Strict::String
291
+
292
+ # ignored if chrome_button_text2 is not set
293
+ attribute? :chrome_button_url2, Types::Strict::String
294
+
295
+ # Firefox-related
296
+
297
+ # optional. You can specify message header here
298
+ attribute? :firefox_title, Types::Strict::String
299
+
300
+ # full path URL to the icon or path to the file in extension resources
301
+ attribute? :firefox_icon, Types::Strict::String
302
+
303
+ def to_json(options = nil)
304
+ attributes.to_json(options)
305
+ end
306
+
307
+ def inspect
308
+ attrs = attributes.map { |k, v| " #{k}=#{v.inspect}" }.join
309
+ "#<#{self.class}#{attrs}>"
310
+ end
311
+ end
312
+ end
@@ -0,0 +1,22 @@
1
+ module Pwush
2
+ class Request
3
+ attr_reader :body
4
+
5
+ def initialize(auth:, app:, payload: nil)
6
+ @auth = auth
7
+ @app = app
8
+ @payload = payload || {}
9
+ @body = build_body(@payload)
10
+ end
11
+
12
+ def to_json
13
+ Oj.dump(body)
14
+ end
15
+
16
+ private
17
+
18
+ def build_body(payload)
19
+ { request: payload.merge(auth: @auth, application: @app) }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,55 @@
1
+ module Pwush
2
+ module Response
3
+ class Deffered
4
+ include Dry::Monads::Result::Mixin
5
+
6
+ def initialize(raw_result)
7
+ @_raw_result = raw_result
8
+ end
9
+
10
+ def resolve
11
+ return http_request_failure if raw_result.status != 200
12
+ return api_request_failure if value_from_api.status_code != 200
13
+ api_request_succesful
14
+ end
15
+
16
+ private
17
+
18
+ def http_request_failure
19
+ Failure.new(value_from_http)
20
+ end
21
+
22
+ def api_request_failure
23
+ Failure.new(value_from_api)
24
+ end
25
+
26
+ def api_request_succesful
27
+ Success.new(value_from_api)
28
+ end
29
+
30
+ def raw_result
31
+ @_raw_result
32
+ end
33
+
34
+ def parsed_result
35
+ @_parsed_result ||= raw_result.parse
36
+ end
37
+
38
+ def value_from_http
39
+ @_value_from_http ||= Value.new(
40
+ status_code: raw_result.status,
41
+ status_message: raw_result.reason,
42
+ body: nil
43
+ )
44
+ end
45
+
46
+ def value_from_api
47
+ @_value_from_api ||= Value.new(
48
+ status_code: parsed_result['status_code'],
49
+ status_message: parsed_result['status_message'],
50
+ body: parsed_result['response']
51
+ )
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,9 @@
1
+ module Pwush
2
+ module Response
3
+ class Value < Dry::Struct::Value
4
+ attribute :status_code, Types::Coercible::Integer
5
+ attribute? :status_message, Types::Strict::String
6
+ attribute? :body, (Types::Hash | Types::String).optional
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ require 'dry/monads/result'
2
+
3
+ require 'pwush/response/deffered'
4
+ require 'pwush/response/value'
5
+
6
+ module Pwush
7
+ module Response
8
+ include Dry::Monads::Result::Mixin
9
+
10
+ def self.wrap
11
+ Deffered.new(yield).resolve
12
+ rescue HTTP::TimeoutError => e
13
+ Failure.new(e)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ require 'dry-struct'
2
+
3
+ module Pwush
4
+ module Types
5
+ include Dry.Types()
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Pwush
2
+ VERSION = '0.3.1'.freeze
3
+ end
data/lib/pwush.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'pwush/config'
2
+
3
+ require 'pwush/types'
4
+ require 'pwush/message'
5
+
6
+ require 'pwush/response'
7
+ require 'pwush/request'
8
+
9
+ require 'pwush/client'
10
+
11
+ module Pwush
12
+ def self.new(options)
13
+ Client.new(options)
14
+ end
15
+ end
data/pwush.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'pwush/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'njiuko-pwush'
7
+ spec.version = Pwush::VERSION
8
+ spec.authors = ['Yaroslav Litvinov', 'Ralph von der Heyden']
9
+ spec.email = ['beyondthemkad@gmail.com', 'ralph@rvdh.de']
10
+
11
+ spec.summary = 'Pushwoosh remote API ruby toolkit'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/njiuko/pwush'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'bin'
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.required_ruby_version = '>= 2.4.0'
24
+
25
+ spec.add_dependency 'dry-monads', '~> 1.0'
26
+ spec.add_dependency 'dry-struct', '~> 1.0'
27
+ spec.add_dependency 'http', '~> 4.4'
28
+ spec.add_dependency 'oj', '~> 3'
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.16'
31
+ spec.add_development_dependency 'pry-byebug', '~> 3.6'
32
+ spec.add_development_dependency 'rake', '>= 12.3.3'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.3'
35
+ spec.add_development_dependency 'simplecov', '~> 0.16'
36
+ spec.add_development_dependency 'webmock', '~> 3.0'
37
+ end
metadata ADDED
@@ -0,0 +1,227 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: njiuko-pwush
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Yaroslav Litvinov
8
+ - Ralph von der Heyden
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-09-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: dry-monads
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: dry-struct
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: http
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '4.4'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '4.4'
56
+ - !ruby/object:Gem::Dependency
57
+ name: oj
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3'
70
+ - !ruby/object:Gem::Dependency
71
+ name: bundler
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.16'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.16'
84
+ - !ruby/object:Gem::Dependency
85
+ name: pry-byebug
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.6'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.6'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rake
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 12.3.3
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 12.3.3
112
+ - !ruby/object:Gem::Dependency
113
+ name: rspec
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '3.0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '3.0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rspec_junit_formatter
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '0.3'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.3'
140
+ - !ruby/object:Gem::Dependency
141
+ name: simplecov
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '0.16'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '0.16'
154
+ - !ruby/object:Gem::Dependency
155
+ name: webmock
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '3.0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '3.0'
168
+ description: Pushwoosh remote API ruby toolkit
169
+ email:
170
+ - beyondthemkad@gmail.com
171
+ - ralph@rvdh.de
172
+ executables:
173
+ - console
174
+ - setup
175
+ extensions: []
176
+ extra_rdoc_files: []
177
+ files:
178
+ - ".circleci/config.yml"
179
+ - ".gitignore"
180
+ - ".rspec"
181
+ - ".ruby-version"
182
+ - CHANGELOG.md
183
+ - CODE_OF_CONDUCT.md
184
+ - Gemfile
185
+ - LICENSE.txt
186
+ - README.md
187
+ - Rakefile
188
+ - bin/console
189
+ - bin/setup
190
+ - lib/pwush.rb
191
+ - lib/pwush/api/applications.rb
192
+ - lib/pwush/api/devices.rb
193
+ - lib/pwush/api/messages.rb
194
+ - lib/pwush/client.rb
195
+ - lib/pwush/config.rb
196
+ - lib/pwush/message.rb
197
+ - lib/pwush/request.rb
198
+ - lib/pwush/response.rb
199
+ - lib/pwush/response/deffered.rb
200
+ - lib/pwush/response/value.rb
201
+ - lib/pwush/types.rb
202
+ - lib/pwush/version.rb
203
+ - pwush.gemspec
204
+ homepage: https://github.com/njiuko/pwush
205
+ licenses:
206
+ - MIT
207
+ metadata: {}
208
+ post_install_message:
209
+ rdoc_options: []
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: 2.4.0
217
+ required_rubygems_version: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ requirements: []
223
+ rubygems_version: 3.1.6
224
+ signing_key:
225
+ specification_version: 4
226
+ summary: Pushwoosh remote API ruby toolkit
227
+ test_files: []