Skip to content

Commit

Permalink
added create method to models
Browse files Browse the repository at this point in the history
  • Loading branch information
tompesman committed Jun 27, 2014
1 parent 797c3de commit 5c9dd65
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 11 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ it will use that. The configuration is stored in Redis and you add the configura

APNS ([see](https://github.com/9to5/pushr-core#generating-certificates)):
```ruby
Pushr::ConfigurationApns.new(app: 'app_name', connections: 2, enabled: true,
certificate: File.read('certificate.pem'), sandbox: false, skip_check_for_error: false).save
Pushr::ConfigurationApns.create(app: 'app_name', connections: 2, enabled: true,
certificate: File.read('certificate.pem'), sandbox: false, skip_check_for_error: false)
```

The `skip_check_for_error` parameter can be set to `true` or `false`. If set to `true` the APNS service
Expand All @@ -64,16 +64,16 @@ sandbox devices in your production environment you should not set `skip_check_fo

APNS Feedback:
```ruby
Pushr::ConfigurationApnsFeedback.new(app: 'app_name', connections: 1, enabled: true,
feedback_poll: 60).save
Pushr::ConfigurationApnsFeedback.create(app: 'app_name', connections: 1, enabled: true,
feedback_poll: 60)
```

Use this configuration to let a thread check for feedback on all APNS Configurations. It checks every `feedback_poll` in seconds.
There should be only one instance of this configuration type.

GCM ([see](http://developer.android.com/guide/google/gcm/gs.html)):
```ruby
Pushr::ConfigurationGcm.new(app: 'app_name', connections: 2, enabled: true, api: '<api key here>').save
Pushr::ConfigurationGcm.create(app: 'app_name', connections: 2, enabled: true, api: '<api key here>')
```

You can have each provider per app_name and you can have more than one app_name. Use the instructions below to generate
Expand Down Expand Up @@ -135,7 +135,7 @@ Where `<options>` can be:

APNS:
```ruby
Pushr::MessageApns.new(
Pushr::MessageApns.create(
app: 'app_name',
device: '<APNS device_token here>',
alert: 'Hello World',
Expand All @@ -144,14 +144,14 @@ Pushr::MessageApns.new(
expiry: 1.day.from_now.to_i,
attributes_for_device: {key: 'MSG'},
priority: 10,
content_available: 1).save
content_available: 1)
```


Silent Push Notification via APNS:

```ruby
Push::MessageApns.create(
Pushr::MessageApns.create(
app: 'app_name',
device: '<APNS device_token here>',
alert: nil,
Expand All @@ -167,7 +167,7 @@ Use `content_available: 1` if the iOS device should start your app upon receivin

GCM:
```ruby
Pushr::MessageGcm.new(
Pushr::MessageGcm.create(
app: 'app_name',
registration_ids: ['<GCM registration_id here>', '<GCM registration_id here>'],
notification_key: 'notification_key_name',
Expand All @@ -176,7 +176,7 @@ Pushr::MessageGcm.new(
time_to_live: 24 * 60 * 60,
restricted_package_name: 'com.example.gcm',
dry_run: false,
collapse_key: 'MSG').save
collapse_key: 'MSG')
```

## Feedback processing
Expand Down
6 changes: 6 additions & 0 deletions lib/pushr/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def save
end
end

def self.create(attributes = {})
m = new(attributes)
m.save
m
end

def delete
Pushr::Core.redis { |conn| conn.hdel('pushr:configurations', key) }
end
Expand Down
6 changes: 6 additions & 0 deletions lib/pushr/feedback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ def save
end
end

def self.create(attributes = {})
m = new(attributes)
m.save
m
end

def to_json
MultiJson.dump(to_hash)
end
Expand Down
6 changes: 6 additions & 0 deletions lib/pushr/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def save
end
end

def self.create(attributes = {})
m = new(attributes)
m.save
m
end

def to_json
MultiJson.dump(to_hash)
end
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/pushr/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@
end
end

describe 'create' do
subject { Pushr::ConfigurationDummy.create(app: 'app_name', connections: 2, enabled: true) }
it 'should create a message' do
expect(subject.valid?).to eql true
end

it 'should create a ConfigurationDummy class' do
expect(subject.class).to eql Pushr::ConfigurationDummy
end
end

describe 'find' do
let!(:config) { Pushr::ConfigurationDummy.new(app: 'app_name', connections: 2, enabled: true) }
it 'should find a configuration' do
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/pushr/feedback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,15 @@
expect(Pushr::Feedback.next).to be_kind_of(Pushr::FeedbackDummy)
end
end

describe 'create' do
subject { Pushr::FeedbackDummy.create(app: 'app_name', device: 'a' * 64, follow_up: 'delete', failed_at: Time.now) }
it 'should create a message' do
expect(subject.valid?).to eql true
end

it 'should create a FeedbackDummy class' do
expect(subject.class).to eql Pushr::FeedbackDummy
end
end
end
13 changes: 12 additions & 1 deletion spec/lib/pushr/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
end
end

describe 'next' do
describe 'save' do
let(:message) { Pushr::MessageDummy.new(app: 'app_name') }
let(:message_invalid) { Pushr::MessageDummy.new }
it 'should return true' do
Expand All @@ -30,4 +30,15 @@
expect(Pushr::Message.next('pushr:app_name:dummy')).to be_kind_of(Pushr::MessageDummy)
end
end

describe 'create' do
subject { Pushr::MessageDummy.create(app: 'app_name') }
it 'should create a message' do
expect(subject.valid?).to eql true
end

it 'should create a MessageDummy class' do
expect(subject.class).to eql Pushr::MessageDummy
end
end
end

0 comments on commit 5c9dd65

Please sign in to comment.