Skip to content

Commit

Permalink
Merge pull request #4 from Kandiie/cr_updates_readme
Browse files Browse the repository at this point in the history
Update readme file
  • Loading branch information
carlosguerreroo committed Mar 12, 2016
2 parents d35a239 + 04e1495 commit e53f99e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end
```ruby
# Device token
token = '900f9e35cc09ab9f3d99f0b244e23f160e0264f1aaf785549efeb6835a586710'
# platform should be :ios or :android
# platform is :ios or :android
# (Any other value will return a RuntimeError)
platform = :ios
# Notification message
Expand All @@ -44,8 +44,24 @@ message = 'Hello World!!!'
push = PushBot::One.new(platform, token, message, sound, options)
push.send # Delivers the notification
```

#### Multiple device notification
```ruby
# platform is an array of valid plataforms (ios or android)
# (Any other value will return a RuntimeError)
platforms = [:ios, :android]
# Notification message
message = 'Hello World!!!'
# Notification schedule (Delivery time)
schedule = DateTime.now
# Build up the notification
# platform, message, schedule (required parameters).
# options (custom fields) (optional parameter)
push = PushBot::All.new(platforms, message, schedule, options = {})
push.send # Delivers the notification
```

##### You can read Pushbots API response using:
Read more about HTTP codes [here](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
```ruby
# Your notification response
push.response
Expand All @@ -57,6 +73,7 @@ push.response.message
push.response.to_s
```

Read more about HTTP codes [here](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Kandiie/pushbots. 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.
Expand Down
13 changes: 8 additions & 5 deletions lib/pushbots/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ class Push

def initialize(platform, message, type)
self.type = type
validates_platform(platform) if type == :one
validates_platforms(platform) if type == :all
self.platform = PLATFORM_TYPE[platform] if type == :one
self.platform = platform.map { |t| PLATFORM_TYPE[t] } if type == :all
if type == :one
validates_platform(platform)
self.platform = PLATFORM_TYPE[platform]
elsif type == :all
validates_platforms(platform)
self.platform = platform.map { |t| PLATFORM_TYPE[t] }
end
self.message = message
self.status = STATUS[:created]
end
Expand All @@ -27,7 +30,7 @@ def platform
private

def validates_platform(platform)
raise 'platform is not valid' if PLATFORM_TYPE[platform].nil?
fail 'platform is not valid' if PLATFORM_TYPE[platform].nil?
end

def validates_platforms(platforms)
Expand Down

0 comments on commit e53f99e

Please sign in to comment.