Skip to content

Commit

Permalink
fix version conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Helperhaps committed Apr 29, 2016
2 parents e5e2a79 + 049272f commit 5c3613b
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 155 deletions.
24 changes: 11 additions & 13 deletions docs/Guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ push_payload = JPush::Push::PushPayload.new(
audience: 'all',
notification: 'hello jpush',
message: 'hello world'
).build
)
pusher.push(push_payload)
```

Expand All @@ -66,15 +66,13 @@ audience.set_tag(tag)
audience.set_tag_and(tag_and)
audience.set_alias(alis)
audience.set_registration_id(registration_ids)
audience.build

# 链式调用
audience = JPush::Push::Audience.new.
set_tag(tag).
set_tag_and(tag_and).
set_alias(alis).
set_registration_id(registration_ids).
build
set_registration_id(registration_ids)
```

参数说明
Expand All @@ -100,7 +98,7 @@ notification = JPush::Push::Notification.new
###### alert

```ruby
notification.set_alert(alert).build
notification.set_alert(alert)
```

###### android
Expand All @@ -111,7 +109,7 @@ notification.set_android(
title: title,
builder_id: builder_id,
extras: extras
).build
)
```

参数说明
Expand All @@ -133,7 +131,7 @@ notification.set_ios(
available: available,
category: category,
extras: extras
).build
)
```

参数说明
Expand Down Expand Up @@ -164,7 +162,7 @@ notification = JPush::Push::Notification.new.
available: available,
category: category,
extras: extras
).build
)
```

#### 构建 PushPayload 对象
Expand All @@ -175,8 +173,8 @@ notification = JPush::Push::Notification.new.

```ruby
# audience 和 notification 对象可按照上面的例子实例化
audience = JPush::Push::Andience.new.set_registration_id(registration_ids).build
notification = JPush::Push::Notification.new.set_alert(alert).build
audience = JPush::Push::Andience.new.set_registration_id(registration_ids)
notification = JPush::Push::Notification.new.set_alert(alert)
```

```ruby
Expand All @@ -186,7 +184,7 @@ push_payload = JPush::Push::PushPayload.new(
audience: audience,
notification: notification,
message: message
).build
)
```

参数说明
Expand All @@ -210,7 +208,7 @@ push_payload = JPush::Push::PushPayload.new(
title: title,
content_type: content_type,
extras: extras
).build
)
```

参数说明
Expand Down Expand Up @@ -282,7 +280,7 @@ push_payload = JPush::Push::PushPayload.new(
content_type: content_type,
extras: extras
).set_sms_message(content, delay_time).
set_options(options).build
set_options(options)
```

#### 推送消息
Expand Down
6 changes: 1 addition & 5 deletions lib/jpush/push/audience.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ def set_registration_id(registration_ids)
self
end

def build
def to_hash
@audience = {
tag: @tag,
tag_and: @tag_and,
alias: @alias,
registration_id: @registration_id
}.compact
raise Utils::Exceptions::JPushError, 'Audience can not be empty.' if @audience.empty?
self
end

def to_hash
@audience
end

Expand Down
6 changes: 1 addition & 5 deletions lib/jpush/push/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@ def set_ios(alert: , sound: nil, badge: nil, available: nil, category:nil, extra
self
end

def build
def to_hash
@notification = {
alert: @alert,
android: @android,
ios: @ios
}.compact
raise Utils::Exceptions::JPushError, 'Notification can not be empty.' if @notification.empty?
self
end

def to_hash
@notification
end

Expand Down
9 changes: 1 addition & 8 deletions lib/jpush/push/push_payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class PushPayload
extend Helper::ArgumentHelper
using Utils::Helper::ObjectExtensions

attr_reader :platform, :audience, :notification, :message, :sms_message, :options

VALID_OPTION_KEY = [:sendno, :time_to_live, :override_msg_id, :apns_production, :big_push_duration]
MAX_SMS_CONTENT_SIZE = 480
MAX_SMS_DELAY_TIME = 86400 # 24 * 60 * 60 (second)
Expand All @@ -36,7 +34,7 @@ def set_options(opts)
self
end

def build
def to_hash
raise Utils::Exceptions::MissingArgumentError.new(['audience']) unless @audience
err_msg = 'missing notification or message'
raise Utils::Exceptions::JPushError, err_msg unless @notification || @message
Expand All @@ -48,11 +46,6 @@ def build
sms_message: @sms_message,
options: @options
}.compact
self
end

def to_hash
@push_payload
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/jpush/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def show(schedule_id)
# 修改指定的Schedule
# PUT https://api.jpush.cn/v3/schedules/{schedule_id}
def update(schedule_id, name: nil, enabled: nil, trigger: nil, push: nil)
hash = SchedulePayload.new(name, trigger, push, enabled).build_update.to_hash
Http::Client.put(base_url + schedule_id, body: hash)
body = SchedulePayload.new(name, trigger, push, enabled).to_update_hash
Http::Client.put(base_url + schedule_id, body: body)
end

# 删除指定的Schedule任务
Expand Down
10 changes: 3 additions & 7 deletions lib/jpush/schedule/schedule_payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ def initialize(name, trigger, push_payload, enabled = nil)
@enabled = enabled
end

def build_update
def to_update_hash
@schedule_payload = {
name: @name,
enabled: @enabled,
trigger: @trigger,
push: @push_payload
}.compact
raise Utils::Exceptions::JPushError, 'Schedule update body can not be empty' if @schedule_payload.empty?
self
@schedule_payload
end

def build
def to_hash
@schedule_payload = {
name: @name,
enabled: true,
Expand All @@ -35,10 +35,6 @@ def build
}
hash = @schedule_payload.select { |_, value| value.nil? }
raise Utils::Exceptions::MissingArgumentError.new(hash.keys) unless hash.empty?
self
end

def to_hash
@schedule_payload
end

Expand Down
6 changes: 1 addition & 5 deletions lib/jpush/schedule/trigger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,12 @@ def set_periodical(start_time, end_time, time, time_unit, frequency, point)
self
end

def build
def to_hash
@trigger = {
single: @single,
periodical: @periodical
}.compact
raise Utils::Exceptions::JPushError, 'Trigger can not be empty.' if @trigger.empty?
self
end

def to_hash
@trigger
end

Expand Down
2 changes: 1 addition & 1 deletion lib/jpush/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module JPush
VERSION = "4.0.1"
VERSION = "4.0.2"
end
6 changes: 3 additions & 3 deletions test/jpush/push/audience_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def setup

def test_new_audience
assert_raises Utils::Exceptions::JPushError do
@audience.build
@audience.to_hash
end
end

def test_set_tag
result = @audience.set_tag('jpush').build.to_hash
result = @audience.set_tag('jpush').to_hash

assert_equal 1, result.size
assert_true result.has_key?(:tag)
Expand All @@ -28,7 +28,7 @@ def test_sets
set_tag_and('jpush').
set_alias('jpush').
set_registration_id('jpush').
build.to_hash
to_hash

assert_equal 4, result.size
assert_true result[:tag].include?('jpush')
Expand Down
9 changes: 4 additions & 5 deletions test/jpush/push/notification_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def setup

def test_new_notification
assert_raises Utils::Exceptions::JPushError do
@notification.build
@notification.to_hash
end
end

def test_set_alert
result = @notification.set_alert('jpush').build.to_hash
result = @notification.set_alert('jpush').to_hash
assert_equal 1, result.size
assert_true result.has_key?(:alert)
assert_true result[:alert].include?('jpush')
Expand All @@ -25,8 +25,7 @@ def test_alert_sets
result = @notification.
set_alert('Hello JPush').
set_android(alert: 'Hello Android').
set_ios(alert: 'Hello IOS').
build.to_hash
set_ios(alert: 'Hello IOS').to_hash
assert_equal 3, result.size
assert_true result.has_key?(:alert)
assert_true result.has_key?(:android)
Expand All @@ -53,7 +52,7 @@ def test_sets
key2: 'value2',
key3: 'value3'
}
).build.to_hash
).to_hash
assert_equal 3, result.size
assert_true result.has_key?(:alert)
assert_true result.has_key?(:android)
Expand Down
Loading

0 comments on commit 5c3613b

Please sign in to comment.