hsquare 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fc918c686257ac4d8b60bcc048478af856fc2c5d
4
+ data.tar.gz: 384c6efac79fedb378ff6cc33cc8b4f577e90059
5
+ SHA512:
6
+ metadata.gz: 9cb102be70277076f0b11bf91538e0f68eb61e17f25df3ba74df3e461c1ac2a0e3d03d3edbdfd54b333b42a755a62bc9c3a00a25b4360df13d52c6b0973e2dc0
7
+ data.tar.gz: 81ada066c79ce2686a76b73b3e8994e0fb0d76b68d8b0bd1133f3a60e8fbabb8d8c1f4ea62805b7b7beb2dc538d305629061ff87eddfba4fe5f8314b6c242a4e
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hsquare.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ end
@@ -0,0 +1,33 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+
17
+ # Rails example
18
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
19
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
20
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
21
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
22
+ watch('config/routes.rb') { "spec/routing" }
23
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
24
+ watch('spec/rails_helper.rb') { "spec" }
25
+
26
+ # Capybara features specs
27
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
28
+
29
+ # Turnip features and steps
30
+ watch(%r{^spec/acceptance/(.+)\.feature$})
31
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
32
+ end
33
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Inbeom Hwang
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,106 @@
1
+ # Hsquare
2
+
3
+ Hsquare는 [Kakao developers](http://developers.kakao.com) Open Platform API의
4
+ 루비 클라이언트 라이브러리입니다.
5
+
6
+ 현재는 푸시 알림 기능을 제공하며, 앞으로 인증 및 카카오톡, 카카오스토리 포스팅
7
+ 등으로 지원 기능을 확장해 나갈 계획입니다.
8
+
9
+ ## 설치하기
10
+
11
+ 애플리케이션의 Gemfile에 hsquare를 추가합니다:
12
+
13
+ gem 'hsquare'
14
+
15
+ Bundler를 이용해 설치합니다:
16
+
17
+ $ bundle
18
+
19
+ ## 사용하기
20
+
21
+ ### 애플리케이션 생성
22
+
23
+ Hsquare를 사용하려면 Kakao Developers에서 애플리케이션을 생성해야 합니다.
24
+ Kakao Developers에 가입 및 로그인하신 후
25
+ [내 애플리케이션](https://developers.kakao.com/apps) 페이지에서 애플리케이션을
26
+ 생성해 주세요.
27
+
28
+ ### Hsquare 설정
29
+
30
+ 애플리케이션 생성 후, 내 애플리케이션 페이지에서 앱 키를 얻을 수 있습니다.
31
+ 4개의 앱 키 중 Admin 키를 Hsquare에 설정합니다:
32
+
33
+ ```ruby
34
+ # In config/initializers/hsquare.rb
35
+
36
+ Hsquare.config do |config|
37
+ config.admin_key = '내 애플리케이션의 Admin 키'
38
+ end
39
+ ```
40
+
41
+ Admin 키는 외부에 노출되지 않도록 보안에 주의를 기울여야 합니다. 환경 변수
42
+ 등으로 소스 컨트롤에서 분리하여 설정하도록 처리하는 것을 추천합니다.
43
+
44
+ ### 푸시 알림
45
+
46
+ #### 기기의 푸시 토큰 등록
47
+
48
+ 애플리케이션 서버에서 푸시 토큰을 등록해야 한다면 `Hsquare::Device` 클래스의
49
+ 객체를 다음과 같이 생성하고,
50
+
51
+ ```ruby
52
+ device = Hsquare::Device.new(
53
+ id: (애플리케이션 내 기기 ID),
54
+ user_id: (애플리케이션 사용자 ID),
55
+ token: '푸시 토큰',
56
+ type: '(apns 또는 gcm)'
57
+ )
58
+ ```
59
+
60
+ 해당 객체의 `#register` 메소드를 호출하여 기기의 푸시 토큰을 등록할 수
61
+ 있습니다.
62
+
63
+ ```ruby
64
+ device.register # Open Platform API가 호출됩니다.
65
+ ```
66
+
67
+ 클라이언트에서 푸시 토큰을 등록하도록 처리되어 있다면 이 과정은 거치지 않아도
68
+ 됩니다.
69
+
70
+ #### 알림 전송
71
+
72
+ `Hsquare::Notification` 클래스의 객체를 생성하고 `#deliver` 메소드로 알림을
73
+ 전송합니다.
74
+
75
+ `Hsquare::Notification` 클래스는 다음과 같이 생성합니다. 각 인자의 의미는 이
76
+ 젬의 소스 코드나 Kakao Developers의 [API 소개 페이지](https://developers.kakao.com/docs/restapi#푸시-알림-푸시-알림-보내기)를
77
+ 참조하세요:
78
+
79
+ ```ruby
80
+ notification = Hsquare::Notification.new(
81
+ recipient_ids: [1, 2, 3], # 알림을 받을 사용자 ID의 목록
82
+ message: 'Hello world!' # 전송할 알림 메시지
83
+ badge: 0 # 뱃지 카운트 (iOS only)
84
+ sound: 'default' # 알림 시 재생할 소리 (iOS only)
85
+ push_alert: true # 푸시 알림 여부 (iOS only, default: true)
86
+ collapse: nil # GCM collapse key (Android only)
87
+ idle_delay: false # 사용자 기기 상태에 따른 알림 전송 시점 변경 (Android only)
88
+ extra: {} # 추가 Payload
89
+ )
90
+
91
+ notification.deliver # 알림을 전송하는 Open Platform API를 호춣합니다.
92
+ ```
93
+
94
+ #### 푸시 토큰 등록 해제
95
+
96
+ 기기 푸시 토큰 등록에서와 같은 방법으로 `Hsquare::Device` 객체를 생성하고 해당
97
+ 객체의 `#unregister` 메소드를 호출하여 기기의 푸시 토큰을 등록 해제할 수
98
+ 있습니다.
99
+
100
+ ## Contributing
101
+
102
+ 1. Fork it ( https://github.com/inbeom/hsquare/fork )
103
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
104
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
105
+ 4. Push to the branch (`git push origin my-new-feature`)
106
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hsquare/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'hsquare'
8
+ spec.version = Hsquare::VERSION
9
+ spec.authors = ['Inbeom Hwang']
10
+ spec.email = ['hwanginbeom@gmail.com']
11
+ spec.summary = %q{Client library for Kakao Developers Open Platform API}
12
+ spec.description = %q{Client library for Kakao Developers Open Platform API}
13
+ spec.homepage = 'https://github.com/inbeom/hsquare'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'httparty'
22
+
23
+ spec.add_development_dependency 'bundler', "~> 1.6"
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ end
@@ -0,0 +1,44 @@
1
+ require 'httparty'
2
+
3
+ require 'hsquare/version'
4
+ require 'hsquare/configuration'
5
+ require 'hsquare/client'
6
+ require 'hsquare/device'
7
+ require 'hsquare/notification'
8
+
9
+ module Hsquare
10
+ # Public: Configures Hsquare with given block.
11
+ #
12
+ # Examples
13
+ #
14
+ # Hsqure.config do |config|
15
+ # config.admin_key = # Admin key obtained from Kakao Developers
16
+ # end
17
+ #
18
+ # Returns newly set configuration.
19
+ def self.config
20
+ if block_given?
21
+ Hsquare::Configuration.new.tap do |configuration|
22
+ yield(configuration)
23
+ apply(configuration)
24
+ end
25
+ else
26
+ @configuration ||= Hsquare::Configuration.new
27
+ end
28
+ end
29
+
30
+ # Public: Applies given configuration.
31
+ #
32
+ # Returns nothing.
33
+ def self.apply(configuration)
34
+ Hsquare::Client::Admin.admin_key = configuration.admin_key if configuration.admin_key
35
+
36
+ if configuration.http_proxy
37
+ http_proxy_uri = URI.parse(configuration.http_proxy)
38
+
39
+ Hsquare::Client.http_proxy http_proxy_uri.host, http_proxy_uri.port
40
+ end
41
+
42
+ @configuration = configuration
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ module Hsquare
2
+ # Public: HTTP(S) client for Kakao API.
3
+ class Client
4
+ include HTTParty
5
+
6
+ # Public: HTTP(S) client for Kakao API with Admin access.
7
+ class Admin < Client
8
+ base_uri 'https://kapi.kakao.com'
9
+
10
+ # Public: Getter for admin_key.
11
+ #
12
+ # Returns String of admin key.
13
+ def self.admin_key
14
+ @admin_key
15
+ end
16
+
17
+ # Public: Setter for admin_key.
18
+ #
19
+ # admin_key - Admin key to newly set.
20
+ #
21
+ # Returns nothing.
22
+ def self.admin_key=(admin_key)
23
+ @admin_key = admin_key
24
+
25
+ default_options.merge!(headers: { 'Authorization' => "KakaoAK #{admin_key}" })
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ module Hsquare
2
+ # Public: Configuration object for Hsquare.
3
+ class Configuration
4
+ # Public: Admin access key of Kakao application.
5
+ attr_accessor :admin_key
6
+
7
+ # Public: HTTP proxy URI.
8
+ attr_accessor :http_proxy
9
+ end
10
+ end
@@ -0,0 +1,88 @@
1
+ module Hsquare
2
+ # Public: APNS/GCM devices with push tokens.
3
+ class Device
4
+ # Public: ID of the device.
5
+ attr_accessor :id
6
+
7
+ # Public: ID of owner of the device.
8
+ attr_accessor :user_id
9
+
10
+ # Public: Push token received from service providers.
11
+ attr_accessor :token
12
+
13
+ # Public: Type of the device.
14
+ attr_accessor :type
15
+
16
+ # Public: Fetch devices for given user.
17
+ #
18
+ # user_or_user_id - User or ID of user.
19
+ #
20
+ # Returns Array of HSquare::Device objects retrieved from the server.
21
+ def self.find_by_user_id(user_or_user_id)
22
+ user_id = user_or_user_id.respond_to?(:id) ? user_or_user_id.id : user_or_user_id
23
+ response = Hsquare::Client::Admin.get('/v1/push/tokens', query: { uuid: user_id })
24
+
25
+ response.parsed_response.map do |device_response|
26
+ new(device_response.symbolize_keys)
27
+ end
28
+ end
29
+
30
+ # Public: Initializes new APNS type device.
31
+ #
32
+ # attributes - Attributes of the device.
33
+ # :id, :device_id - ID of the device.
34
+ # :user_id, :uuid - ID of the owner.
35
+ # :token, :push_token - Push token of the device.
36
+ #
37
+ # Returns newly initialized APNS device.
38
+ def self.apns(attributes = {})
39
+ new(attributes.merge(type: 'apns'))
40
+ end
41
+
42
+ # Public: Initializes new GCM type device.
43
+ #
44
+ # attributes - Attributes of the device.
45
+ # :id, :device_id - ID of the device.
46
+ # :user_id, :uuid - ID of the owner.
47
+ # :token, :push_token - Push token of the device.
48
+ #
49
+ # Returns newly initialized APNS device.
50
+ def self.gcm(attributes = {})
51
+ new(attributes.merge(type: 'gcm'))
52
+ end
53
+
54
+ # Public: Initializes new device object.
55
+ #
56
+ # attributes - Attributes of the device.
57
+ # :id, :device_id - ID of the device.
58
+ # :type, :push_type - Type of the device.
59
+ # :user_id, :uuid - ID of the owner.
60
+ # :token, :push_token - Push token of the device.
61
+ #
62
+ # Returns newly iniitalized device object.
63
+ def initialize(attributes = {})
64
+ @id = attributes[:id] || attributes[:device_id]
65
+ @user_id = attributes[:user_id] || attributes[:uuid]
66
+ @token = attributes[:token] || attributes[:push_token]
67
+ @type = attributes[:type] || attributes[:push_type]
68
+ end
69
+
70
+ # Public: Registers the device via Kakao API.
71
+ #
72
+ # Returns Number of days before invalidation.
73
+ def register
74
+ Hsquare::Client::Admin.post('/v1/push/register', body: {
75
+ uuid: user_id, device_id: id, push_type: type, push_token: token.gsub(/\s/, '')
76
+ })
77
+ end
78
+
79
+ # Public: Unregisters the device via Kakao API.
80
+ #
81
+ # Returns Number of days before invalidation.
82
+ def unregister
83
+ Hsquare::Client::Admin.post('/v1/push/deregister', body: {
84
+ uuid: user_id, device_id: id, push_type: type
85
+ })
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,104 @@
1
+ module Hsquare
2
+ # Public: Notification entries sent to Kakao push.
3
+ class Notification
4
+ # Public: Array of recipient IDs.
5
+ attr_accessor :recipient_ids
6
+
7
+ # Public: Message (alert in APNS) displayed to recipients.
8
+ attr_accessor :message
9
+
10
+ # Public: Badge count to set.
11
+ attr_accessor :badge
12
+
13
+ # Public: Sound to play.
14
+ attr_accessor :sound
15
+
16
+ # Public: Whether notification is delivered through notification center.
17
+ attr_accessor :push_alert
18
+
19
+ # Public: Collapse key for GCM.
20
+ attr_accessor :collapse
21
+
22
+ # Public: Whether GCM message delivery is delayed while device is idle.
23
+ attr_accessor :idle_delay
24
+
25
+ # Public: Extra payload.
26
+ attr_accessor :extra
27
+
28
+ # Public: Initializes new notification object.
29
+ #
30
+ # attributes - Attributes of the notification.
31
+ # :recipient_id - ID of recipient (optinoal).
32
+ # :recipient_ids - List of IDs of recipients (optinoal).
33
+ # :message - Message displayed to recipients (optional).
34
+ # :badge - Badge count (optinoal).
35
+ # :sound - Sound to play (optinoal).
36
+ # :push_alert - Whether notification is delivered through
37
+ # notification center (default: true).
38
+ # :collapse - Collapse key for GCM (optional).
39
+ # :idle_delay - Whether GCM message delivery is delayed
40
+ # while device is idle (default: false).
41
+ # :extra - Extra payload (optinoal).
42
+ #
43
+ # Returns newly initialized notification object.
44
+ def initialize(attributes = {})
45
+ @recipient_ids = (attributes[:recipient_id] && [attributes[:recipient_id]]) || attributes[:recipient_ids]
46
+ @message = attributes[:message]
47
+ @badge = attributes[:badge]
48
+ @sound = attributes[:sound]
49
+ @push_alert = attributes.has_key?(:push_alert) ? attributes[:push_alert] : true
50
+ @collapse = attributes[:collapse]
51
+ @idle_delay = attributes.has_key?(:idle_delay) ? attributes[:idle_delay] : false
52
+ @extra = attributes[:extra]
53
+ end
54
+
55
+ # Public: Helper method to set recipient_ids with single ID.
56
+ #
57
+ # recipient_id - ID of single recipient.
58
+ #
59
+ # Returns 1-length array of recipient_id.
60
+ def recipient_id=(recipient_id)
61
+ @recipient_ids = [recipient_id]
62
+ end
63
+
64
+ # Public: Delivers notification to recipients' devices.
65
+ #
66
+ # Returns nothing.
67
+ def deliver
68
+ Hsquare::Client::Admin.post('/v1/push/send', body: payload)
69
+ end
70
+
71
+ protected
72
+
73
+ # Internal: Payload delivered to push send API.
74
+ #
75
+ # Returns Hash of request body.
76
+ def payload
77
+ { uuids: recipient_ids.to_json, push_message: { for_apns: apns_payload, for_gcm: gcm_payload }.to_json }
78
+ end
79
+
80
+ # Internal: Payload for APNS.
81
+ #
82
+ # Returns Hash of APNS payload.
83
+ def apns_payload
84
+ {
85
+ badge: badge,
86
+ sound: sound,
87
+ push_alert: push_alert,
88
+ message: message,
89
+ custom_field: extra
90
+ }.keep_if { |_, v| !v.nil? }
91
+ end
92
+
93
+ # Internal: Payload for GCM.
94
+ #
95
+ # Returns Hash of GCM payload.
96
+ def gcm_payload
97
+ {
98
+ collapse: collapse,
99
+ delay_while_idle: idle_delay,
100
+ custom_field: (extra || {}).merge(message: message)
101
+ }.keep_if { |_, v| !v.nil? }
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,3 @@
1
+ module Hsquare
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Hsquare::Client do
4
+ describe Hsquare::Client::Admin do
5
+ describe '#admin_key=' do
6
+ let(:admin_key) { 'admin-key' }
7
+
8
+ it { expect { Hsquare::Client::Admin.admin_key = admin_key }.to change { Hsquare::Client::Admin.default_options } }
9
+ it { expect { Hsquare::Client::Admin.admin_key = admin_key }.not_to change { Hsquare::Client.default_options } }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Hsquare::Device do
4
+ describe '.find_by_user_id' do
5
+ let(:user_id) { 123 }
6
+ let(:mock_response) { double(parsed_response: []) }
7
+
8
+ it { expect(Hsquare::Client::Admin).to receive(:get).with('/v1/push/tokens', query: { uuid: user_id }).and_return(mock_response); Hsquare::Device.find_by_user_id(user_id) }
9
+ end
10
+
11
+ describe '#initialize' do
12
+ let(:attributes) { {} }
13
+ let(:device) { Hsquare::Device.new(attributes) }
14
+
15
+ context 'when attributes is set with proper values' do
16
+ let(:attributes) { { id: 2, type: 'apns', user_id: 3, token: 'token' } }
17
+
18
+ it { expect(device.id).to eq(attributes[:id]) }
19
+ it { expect(device.type).to eq(attributes[:type]) }
20
+ it { expect(device.user_id).to eq(attributes[:user_id]) }
21
+ it { expect(device.token).to eq(attributes[:token]) }
22
+ end
23
+
24
+ context 'when attributes is set with values from API response' do
25
+ let(:attributes) { { device_id: 2, push_type: 'apns', uuid: 3, push_token: 'token' } }
26
+
27
+ it { expect(device.id).to eq(attributes[:device_id]) }
28
+ it { expect(device.type).to eq(attributes[:push_type]) }
29
+ it { expect(device.user_id).to eq(attributes[:uuid]) }
30
+ it { expect(device.token).to eq(attributes[:push_token]) }
31
+ end
32
+ end
33
+
34
+ describe '#register' do
35
+ let(:attributes) { { id: 1, user_id: 2, type: 'apns', token: 'token' } }
36
+ let(:device) { Hsquare::Device.new(attributes) }
37
+
38
+ it { expect(Hsquare::Client::Admin).to receive(:post).with('/v1/push/register', body: { uuid: device.user_id, device_id: device.id, push_type: device.type, push_token: device.token }); device.register }
39
+ end
40
+
41
+ describe '#unregister' do
42
+ let(:attributes) { { id: 1, user_id: 2, type: 'apns', token: 'token' } }
43
+ let(:device) { Hsquare::Device.new(attributes) }
44
+
45
+ it { expect(Hsquare::Client::Admin).to receive(:post).with('/v1/push/deregister', body: { uuid: device.user_id, device_id: device.id, push_type: device.type }); device.unregister }
46
+ end
47
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Hsquare::Notification do
4
+ describe '#deliver' do
5
+ let(:recipient_id) { 123 }
6
+ let(:message) { 'message' }
7
+ let(:notification) { Hsquare::Notification.new(recipient_id: recipient_id, message: message) }
8
+
9
+ it { expect(Hsquare::Client::Admin).to receive(:post).with('/v1/push/send', body: { uuids: [recipient_id].to_json, push_message: { for_apns: { push_alert: true, message: message }, for_gcm: { delay_while_idle: false, custom_field: { message: message } } }.to_json }); notification.deliver }
10
+ end
11
+
12
+ describe '#recipient_id=' do
13
+ let(:recipient_id) { 123 }
14
+ let(:notification) { Hsquare::Notification.new }
15
+
16
+ it { expect { notification.recipient_id = recipient_id }.to change { notification.recipient_ids }.to([recipient_id]) }
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Hsquare do
4
+ describe '.apply' do
5
+ let(:configuration) { Hsquare::Configuration.new }
6
+
7
+ before { Hsquare::Client.default_options.clear }
8
+ before { Hsquare::Client::Admin.default_options.clear }
9
+
10
+ context 'when http_proxy is set' do
11
+ before { configuration.http_proxy = 'http://proxy.com:1234' }
12
+
13
+ it { expect { Hsquare.apply(configuration) }.to change { Hsquare::Client.default_options } }
14
+ it { expect { Hsquare.apply(configuration) }.to change { Hsquare::Client::Admin.default_options } }
15
+ end
16
+
17
+ context 'when admin_key is set' do
18
+ before { configuration.admin_key = 'admin-key' }
19
+
20
+ it { expect { Hsquare.apply(configuration) }.not_to change { Hsquare::Client.default_options } }
21
+ it { expect { Hsquare.apply(configuration) }.to change { Hsquare::Client::Admin.admin_key } }
22
+ it { expect { Hsquare.apply(configuration) }.to change { Hsquare::Client::Admin.default_options } }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ require 'hsquare'
2
+
3
+ RSpec.configure do |config|
4
+ config.order = 'random'
5
+ end
File without changes
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hsquare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Inbeom Hwang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
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
+ description: Client library for Kakao Developers Open Platform API
70
+ email:
71
+ - hwanginbeom@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Guardfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - hsquare.gemspec
83
+ - lib/hsquare.rb
84
+ - lib/hsquare/client.rb
85
+ - lib/hsquare/configuration.rb
86
+ - lib/hsquare/device.rb
87
+ - lib/hsquare/notification.rb
88
+ - lib/hsquare/version.rb
89
+ - spec/lib/hsquare/client_spec.rb
90
+ - spec/lib/hsquare/device_spec.rb
91
+ - spec/lib/hsquare/notification_spec.rb
92
+ - spec/lib/hsquare_spec.rb
93
+ - spec/spec_helper.rb
94
+ - spec/support/mock_client.rb
95
+ homepage: https://github.com/inbeom/hsquare
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.2
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Client library for Kakao Developers Open Platform API
119
+ test_files:
120
+ - spec/lib/hsquare/client_spec.rb
121
+ - spec/lib/hsquare/device_spec.rb
122
+ - spec/lib/hsquare/notification_spec.rb
123
+ - spec/lib/hsquare_spec.rb
124
+ - spec/spec_helper.rb
125
+ - spec/support/mock_client.rb