instapush-api 0.0.1 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32913e2ef8303726317d501aa2f6bf71344861e2
4
- data.tar.gz: 5631ad8dc0c1c21419375a1f861210a7c0e87209
3
+ metadata.gz: 4fbc68ab911f9849e5401f9b0b0f2ba142579712
4
+ data.tar.gz: e1574b911494282baf1ff705eb4ec35bb4401873
5
5
  SHA512:
6
- metadata.gz: e5566cc4c136cb29f770afd415607ef3c4d64e7f36b10ebc8388acad4f3e41dc736b1a009bc8b27f0fcebcbbd310483783c70a0046f84b89f0f2549d43806755
7
- data.tar.gz: 3c54baa16d64a6b18f5b997bbac535b33380d9e4abb045d7bca3eef4ace6a48d7cdab4b0301682a761dcbe911f0f29d898fd57aef25fef428aa592e482c4a06a
6
+ metadata.gz: 2ebf4c725ad68d6b41d1e541333c11c6da1524070cfe572129c62dbc68cdb5d8632d02d7a30137a171875bdb8f587a1867812d331838bc88b3a645291243897d
7
+ data.tar.gz: f9647b511e7d1d1d302a233234dd5cd20b044858680597e3a28dc1e09526f2691aa703b6db706203c925dca02a011c71792d65dd24f0dbc52e65d04249ba2730
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ vendor
@@ -1,3 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 1.9.3
3
4
  - 2.0.0
5
+ - 2.1.0
6
+ - jruby
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Instapush
2
2
 
3
- TODO: Write a gem description
3
+ This library provides an API wrapper for [Instapush.im](http://instapush.im). Instapush.im allows you to send push notification to your Android/iOS mobile from your application.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'instapush'
9
+ gem 'instapush-api'
10
10
 
11
11
  And then execute:
12
12
 
@@ -14,15 +14,26 @@ And then execute:
14
14
 
15
15
  Or install it yourself as:
16
16
 
17
- $ gem install instapush
17
+ $ gem install instapush-api
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Using the library requires only a few lines of code:
22
+
23
+ ```
24
+ require 'instapush'
25
+
26
+ app = Instapush::Application.new 'id', 'secret'
27
+
28
+ event = Instapush::Event.new 'event-name'
29
+ event.tracker= { :version => '0.9.0' }
30
+
31
+ app.push event
32
+ ```
22
33
 
23
34
  ## Contributing
24
35
 
25
- 1. Fork it ( http://github.com/<my-github-username>/instapush/fork )
36
+ 1. Fork it ( http://github.com/halfdan/instapush/fork )
26
37
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
38
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
39
  4. Push to the branch (`git push origin my-new-feature`)
File without changes
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
24
25
  end
@@ -4,10 +4,17 @@ require 'json'
4
4
 
5
5
  module Instapush
6
6
  class Application
7
- def initialize(app_id, app_secret)
7
+ def initialize(app_id, app_secret, opts = {})
8
+ default_options = {
9
+ :use_ssl => false
10
+ }
11
+ @options = default_options.merge(opts)
12
+
8
13
  @app_id = app_id
9
14
  @app_secret = app_secret
10
- @api_url = 'http://api.instapush.im/post'
15
+
16
+ scheme = @options[:use_ssl] ? 'https' : 'http'
17
+ @api_url = "#{scheme}://api.instapush.im/post"
11
18
  end
12
19
 
13
20
  def push(event)
@@ -17,6 +24,10 @@ module Instapush
17
24
 
18
25
  uri = URI.parse(@api_url)
19
26
  http = Net::HTTP.new(uri.host, uri.port)
27
+
28
+ http.use_ssl = @options[:use_ssl];
29
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
30
+
20
31
  request = Net::HTTP::Post.new(uri.request_uri)
21
32
  request.body= data.to_json
22
33
  request.content_type = 'application/json'
@@ -1,3 +1,3 @@
1
1
  module Instapush
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Instapush::Application do
4
+ before(:each) do
5
+ @event = Instapush::Event.new 'event'
6
+ end
7
+
8
+ it 'should fail on invalid push argument' do
9
+ app = Instapush::Application.new 'id', 'secret'
10
+ lambda { app.push('foo')}.should raise_error(ArgumentError)
11
+ end
12
+
13
+ it 'should use HTTP by default' do
14
+ app = Instapush::Application.new 'id', 'secret'
15
+ stub_request(:post, "http://api.instapush.im/post")
16
+
17
+ app.push @event
18
+ end
19
+
20
+ it 'should use HTTPS if requested' do
21
+ app = Instapush::Application.new 'id', 'secret', use_ssl: true
22
+ stub_request(:post, "https://api.instapush.im/post").with(body: {})
23
+
24
+ app.push @event
25
+ end
26
+
27
+ it 'should send the event name in the body' do
28
+ app = Instapush::Application.new 'id', 'secret'
29
+ stub_request(:post, "api.instapush.im/post").with(:body => "{\"event\":\"event\",\"trackers\":{}}")
30
+
31
+ app.push @event
32
+ end
33
+
34
+ it 'should send the app id as POST header' do
35
+ app = Instapush::Application.new 'id', 'secret'
36
+ stub_request(:post, "api.instapush.im/post").with(:body => "{\"event\":\"event\",\"trackers\":{}}", :headers => { 'X-INSTAPUSH-APPSECRET' => 'secret' })
37
+
38
+ app.push @event
39
+
40
+ end
41
+
42
+ it 'should send the app secret as POST header' do
43
+ app = Instapush::Application.new 'id', 'secret'
44
+ stub_request(:post, "api.instapush.im/post").with(:body => "{\"event\":\"event\",\"trackers\":{}}", :headers => { 'X-INSTAPUSH-APPID' => 'id' })
45
+
46
+ app.push @event
47
+ end
48
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Instapush::Event do
4
+ it 'should take a name as parameter' do
5
+ event = Instapush::Event.new 'event'
6
+ event.name.should eq('event')
7
+ end
8
+
9
+ it 'should accept a hash of trackers' do
10
+ event = Instapush::Event.new 'event'
11
+ data = { a: 5, b: 7 }
12
+ event.tracker= data
13
+
14
+ event.tracker.should equal(data)
15
+ end
16
+ end
@@ -4,8 +4,4 @@ describe Instapush do
4
4
  it 'should have a version number' do
5
5
  Instapush::VERSION.should_not be_nil
6
6
  end
7
-
8
- it 'should do something useful' do
9
- false.should be_true
10
- end
11
7
  end
@@ -1,2 +1,3 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'instapush'
3
+ require 'webmock/rspec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instapush-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabian Becker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-25 00:00:00.000000000 Z
11
+ date: 2014-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Instapush.im allows you to send push notifications to your mobile device.
56
70
  This library provides a simple API wrapper for the service.
57
71
  email:
@@ -74,6 +88,8 @@ files:
74
88
  - lib/instapush/application.rb
75
89
  - lib/instapush/event.rb
76
90
  - lib/instapush/version.rb
91
+ - spec/application_spec.rb
92
+ - spec/event_spec.rb
77
93
  - spec/instapush_spec.rb
78
94
  - spec/spec_helper.rb
79
95
  homepage: http://github.com/halfdan/instapush
@@ -101,5 +117,7 @@ signing_key:
101
117
  specification_version: 4
102
118
  summary: Instapush.im API Wrapper
103
119
  test_files:
120
+ - spec/application_spec.rb
121
+ - spec/event_spec.rb
104
122
  - spec/instapush_spec.rb
105
123
  - spec/spec_helper.rb