cloud_five_push 0.1.1 → 1.0.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: 9cac6d8ce09bbcbb5a1a26cfcaa55721384ae44f
4
- data.tar.gz: 831176ac60992f5b5ea1861e6b09ad98bc450a42
3
+ metadata.gz: 65c4d60a60ac7154dad31c52c1bf9f572b1c8160
4
+ data.tar.gz: 151eb3c4e347c4c340f353071e7698ccd615597a
5
5
  SHA512:
6
- metadata.gz: 40a929ae5afd337f6b964b94b97ebad9a77a898c50fbf5a5e6e236a5c3a1d122f21a2ef21cbd2408c1e66f5d7d67c891a1d8efc159a72d05f7e082d483181bd7
7
- data.tar.gz: 87975a51cd08af1b24b151263e579dc92bd4cd109fb8c85e598f31905d6ac553e12d94b82306e179745a27b989e30cf4b08120642ba36c39fc571e1532084981
6
+ metadata.gz: 074e235d847cfaec0328f779ecbef5ab8344fdca808d0b9b8fc59a22cb7b5179a6ba58f6ec3714b35322e2e6a5bbf1f69c7b63c5cc36bce74af23cae1b3a80cc
7
+ data.tar.gz: 3c7b665805de5d5da468a5cce71461e0075240eba9bd5a0cc7c03a7c275de549e4bd2e4bcaaaa22207603065c08997bd2bf6ca86007e2b6ee73156cdf9340101
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ spec/examples.txt
19
+ spec/vcr_cassettes
@@ -21,6 +21,8 @@ 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 "vcr"
25
+ spec.add_development_dependency "webmock"
24
26
 
25
27
  spec.add_dependency "httparty"
26
28
  spec.add_dependency "json"
@@ -1,17 +1,19 @@
1
1
  require 'httparty'
2
+
2
3
  module CloudFivePush
3
4
  class Notification
5
+ include HTTParty
6
+
4
7
  attr_accessor :user_identifiers, :alert, :message, :badge, :scheduled_at, :broadcast,
5
8
  :api_key, :data, :aps_environment, :content_available
6
9
 
7
- include HTTParty
8
10
  base_uri 'https://push.cloudfiveapp.com'
9
11
  # debug_output $stderr
10
12
 
11
- def initialize(api_key=nil)
13
+ def initialize(api_key = nil)
12
14
  @api_key = api_key || CloudFivePush.api_key
13
15
  if @api_key.nil?
14
- raise "api_key is required (or set CloudFivePush.api_key)"
16
+ raise "api_key is required. Pass into initializer or set CloudFivePush.api_key first"
15
17
  end
16
18
  @broadcast = false
17
19
  @user_identifiers = []
@@ -27,7 +29,7 @@ module CloudFivePush
27
29
  raise "Can't both broadcast and set user_identifiers"
28
30
  end
29
31
 
30
- self.class.post('/push/notify', body: push_params)
32
+ self.class.post('/api/push/notify', body: push_params).parsed_response
31
33
  end
32
34
 
33
35
  def user_identifiers=(user_identifiers)
@@ -1,3 +1,3 @@
1
1
  module CloudFivePush
2
- VERSION = "0.1.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,9 +1,58 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe CloudFivePush::Notification do
4
- before(:all) { CloudFivePush.api_key = "fake"; }
3
+ RSpec.describe CloudFivePush::Notification do
4
+ before(:all) { CloudFivePush.api_key = "fake" }
5
+
5
6
  let(:notification) { CloudFivePush::Notification.new }
6
- context "Setting user identifiers" do
7
+
8
+ describe '::new' do
9
+ it 'sets broadcast to false' do
10
+ expect(notification.broadcast).to eq false
11
+ end
12
+
13
+ it 'sets user identifiers to blank array' do
14
+ expect(notification.user_identifiers).to eq []
15
+ end
16
+
17
+ it 'sets the aps_environment from CloudFivePush' do
18
+ CloudFivePush.aps_environment = 'production'
19
+ expect(notification.aps_environment).to eq 'production'
20
+ end
21
+
22
+ it 'raises error if there is no api_key' do
23
+ CloudFivePush.api_key = nil
24
+ expect {
25
+ notification
26
+ }.to raise_error "api_key is required. Pass into initializer or set CloudFivePush.api_key first"
27
+ CloudFivePush.api_key = 'fake'
28
+ end
29
+ end
30
+
31
+ describe '#notify!' do
32
+ it 'posts to the cloud five api url and returns our json' do
33
+ notification.broadcast = true
34
+ expect(notification.notify!).to eq({
35
+ "success"=>false,
36
+ "error"=>"Invalid API key"
37
+ })
38
+ end
39
+
40
+ it 'raises error if broadcast is false and there are no user identifiers' do
41
+ expect{
42
+ notification.notify!
43
+ }.to raise_error "Please set user_identifiers or set broadcast=true"
44
+ end
45
+
46
+ it 'raises error if broadcast is true and there are user identifiers' do
47
+ notification.broadcast = true
48
+ notification.user_identifiers = [1]
49
+ expect{
50
+ notification.notify!
51
+ }.to raise_error "Can't both broadcast and set user_identifiers"
52
+ end
53
+ end
54
+
55
+ describe "#user_identifiers=" do
7
56
  it "accepts an array of identifiers" do
8
57
  notification.user_identifiers = [1,2,3]
9
58
  expect(notification.user_identifiers).to eq [1,2,3]
@@ -15,11 +64,10 @@ describe CloudFivePush::Notification do
15
64
  end
16
65
  end
17
66
 
18
-
19
- it "Uses the global aps_environment setting" do
20
- CloudFivePush.aps_environment = :development
21
- expect(notification.aps_environment).to eq :development
22
- CloudFivePush.aps_environment = nil #reset
67
+ describe '#user_identifier=' do
68
+ it 'is an alias to user_identifiers=' do
69
+ notification.user_identifier = 1
70
+ expect(notification.user_identifiers).to eq [1]
71
+ end
23
72
  end
24
-
25
- end
73
+ end
@@ -1,18 +1,100 @@
1
1
  require 'cloud_five_push'
2
+
2
3
  # This file was generated by the `rspec --init` command. Conventionally, all
3
4
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
4
- # Require this file using `require "spec_helper"` to ensure that it is only
5
- # loaded once.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
6
19
  #
7
20
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+
22
+ # Auto-require all files in the support directory.
23
+ Dir[File.join(__dir__, 'support/**/*.rb')].each { |f| require f }
24
+
8
25
  RSpec.configure do |config|
9
- config.treat_symbols_as_metadata_keys_with_true_values = true
10
- config.run_all_when_everything_filtered = true
26
+ # rspec-expectations config goes here. You can use an alternate
27
+ # assertion/expectation library such as wrong or the stdlib/minitest
28
+ # assertions if you prefer.
29
+ config.expect_with :rspec do |expectations|
30
+ # This option will default to `true` in RSpec 4. It makes the `description`
31
+ # and `failure_message` of custom matchers include text for helper methods
32
+ # defined using `chain`, e.g.:
33
+ # be_bigger_than(2).and_smaller_than(4).description
34
+ # # => "be bigger than 2 and smaller than 4"
35
+ # ...rather than:
36
+ # # => "be bigger than 2"
37
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
38
+ end
39
+
40
+ # rspec-mocks config goes here. You can use an alternate test double
41
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
42
+ config.mock_with :rspec do |mocks|
43
+ # Prevents you from mocking or stubbing a method that does not exist on
44
+ # a real object. This is generally recommended, and will default to
45
+ # `true` in RSpec 4.
46
+ mocks.verify_partial_doubles = true
47
+ end
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ # These two settings work together to allow you to limit a spec run
52
+ # to individual examples or groups you care about by tagging them with
53
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
54
+ # get run.
11
55
  config.filter_run :focus
56
+ config.run_all_when_everything_filtered = true
57
+
58
+ # Allows RSpec to persist some state between runs in order to support
59
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
60
+ # you configure your source control system to ignore this file.
61
+ config.example_status_persistence_file_path = "spec/examples.txt"
62
+
63
+ # Limits the available syntax to the non-monkey patched syntax that is
64
+ # recommended. For more details, see:
65
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
66
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
67
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
68
+ config.disable_monkey_patching!
69
+
70
+ # This setting enables warnings. It's recommended, but in some cases may
71
+ # be too noisy due to issues in dependencies.
72
+ config.warnings = true
73
+
74
+ # Many RSpec users commonly either run the entire suite or an individual
75
+ # file, and it's useful to allow more verbose output when running an
76
+ # individual spec file.
77
+ if config.files_to_run.one?
78
+ # Use the documentation formatter for detailed output,
79
+ # unless a formatter has already been configured
80
+ # (e.g. via a command-line flag).
81
+ config.default_formatter = 'doc'
82
+ end
83
+
84
+ # Print the 10 slowest examples and example groups at the
85
+ # end of the spec run, to help surface which specs are running
86
+ # particularly slow.
87
+ #config.profile_examples = 10
12
88
 
13
89
  # Run specs in random order to surface order dependencies. If you find an
14
90
  # order dependency and want to debug it, you can fix the order by providing
15
91
  # the seed, which is printed after each run.
16
92
  # --seed 1234
17
- config.order = 'random'
93
+ config.order = :random
94
+
95
+ # Seed global randomization in this process using the `--seed` CLI option.
96
+ # Setting this allows you to use `--seed` to deterministically reproduce
97
+ # test failures related to randomization by passing the same `--seed` value
98
+ # as the one that triggered the failure.
99
+ Kernel.srand config.seed
18
100
  end
@@ -0,0 +1,19 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |config|
4
+ config.allow_http_connections_when_no_cassette = true
5
+ config.cassette_library_dir = File.join __dir__, '../vcr_cassettes'
6
+ config.configure_rspec_metadata!
7
+ config.hook_into :webmock
8
+ config.ignore_localhost = true
9
+ end
10
+
11
+ RSpec.configure do |config|
12
+ config.around :each do |example|
13
+ # VCR won't create cassettes for examples that do not make requests
14
+ # so set the vcr metadata for every example
15
+ # so VCR is invoked automagically for every test that makes external requests
16
+ example.metadata[:vcr] = true
17
+ example.run
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_five_push
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Samson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2015-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: httparty
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -99,6 +127,7 @@ files:
99
127
  - lib/cloud_five_push/version.rb
100
128
  - spec/notification_spec.rb
101
129
  - spec/spec_helper.rb
130
+ - spec/support/vcr.rb
102
131
  homepage: ''
103
132
  licenses:
104
133
  - MIT
@@ -126,3 +155,4 @@ summary: Wraps the API for push.cloudfiveapp.com
126
155
  test_files:
127
156
  - spec/notification_spec.rb
128
157
  - spec/spec_helper.rb
158
+ - spec/support/vcr.rb