Skip to content

Commit

Permalink
Merge pull request #29 from lsmolic/feature/refactor
Browse files Browse the repository at this point in the history
feature/refactor
  • Loading branch information
pablonahuelgomez authored Apr 13, 2020
2 parents f425db6 + 4c47413 commit ca9dec5
Show file tree
Hide file tree
Showing 10 changed files with 4,668 additions and 98 deletions.
3,923 changes: 3,923 additions & 0 deletions .rubocop.yml

Large diffs are not rendered by default.

22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Exponent Server SDK Ruby

[![Build Status](https://travis-ci.org/expo/expo-server-sdk-ruby.svg?branch=master)](https://travis-ci.org/expo/expo-server-sdk-ruby)
[![Gem Version](https://badge.fury.io/rb/exponent-server-sdk.svg)](https://badge.fury.io/rb/exponent-server-sdk)

Expand Down Expand Up @@ -28,10 +29,9 @@ $ gem install exponent-server-sdk

### Client

The push client is the preferred way. This hits the latest version of the api.

Optional arguments: `gzip: true`
The push client is the preferred way. This hits the latest version of the api.

Optional arguments: `gzip: true`

```ruby
client = Exponent::Push::Client.new
Expand All @@ -47,9 +47,23 @@ messages = [{
body: "You've got mail"
}]

client.publish messages
# @Deprecated
# client.publish(messages)

# MAX 100 messages at a time
handler = client.send_messages(messages)

# Array of all errors returned from the API
# puts handler.errors

# you probably want to delay calling this because the service might take a few moments to send
# I would recommend reading the expo documentation regarding delivery delays
client.verify_deliveries(handler.receipt_ids)

```

See the getting started example. If you clone this repo, you can also use it to test locally by entering your ExponentPushToken. Otherwise it serves as a good copy pasta example to get you going.

The complete format of the messages can be found [here.](https://docs.expo.io/versions/latest/guides/push-notifications#message-format)

## Contributing
Expand Down
24 changes: 12 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
require "bundler/gem_tasks"
require "rake/testtask"
require 'bundler/gem_tasks'
require 'rake/testtask'

def load_libs(t)
t.libs << "test"
t.libs << "lib"
def load_libs(rake_task)
rake_task.libs << 'test'
rake_task.libs << 'lib'
end

Rake::TestTask.new(:test) do |t|
load_libs t
t.test_files = FileList['test/**/*-test.rb']
Rake::TestTask.new(:test) do |rake_task|
load_libs rake_task
rake_task.test_files = FileList['test/**/*-test.rb']
end

Rake::TestTask.new(:manual_test) do |t|
load_libs t
t.test_files = FileList['manual_test.rb']
Rake::TestTask.new(:getting_started) do |rake_task|
load_libs rake_task
rake_task.test_files = FileList['examples/getting_started.rb']
end

task :default => :test
task default: :test
47 changes: 47 additions & 0 deletions examples/getting_started.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

require 'exponent-server-sdk'

class Test
def initialize
# @client = Exponent::Push::Client.new

# OR use GZIP to be AWESOME
@client = Exponent::Push::Client.new(gzip: true)
end

def too_many_messages
(0..101).map { create_message }
end

def create_message
{
# REPLACE WITH YOUR EXPONENT PUSH TOKEN LIKE:
# to: 'ExponentPushToken[g5sIEbOm2yFdzn5VdSSy9n]',
to: "ExponentPushToken[#{(0...22).map { ('a'..'z').to_a[rand(26)] }.join}]",
sound: 'default',
title: 'Hello World',
subtitle: 'This is a Push Notification',
body: 'Here\'s a little message for you...',
data: {
user_id: 1,
points: 23_434
},
ttl: 10,
expiration: 1_886_207_332,
priority: 'default',
badge: 0,
channelId: 'game'
}
end

def test
# messages = too_many_messages
messages = [create_message]

response_handler = @client.send_messages(messages)
puts response_handler.response.response_body
end
end

Test.new.test
6 changes: 3 additions & 3 deletions exponent-server-sdk.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'exponent-server-sdk/version'

Expand All @@ -21,6 +20,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'typhoeus'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'minitest'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rubocop'
end
Loading

0 comments on commit ca9dec5

Please sign in to comment.