-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from urbanairship/TOOLSLIBS-309-b
Merge in Named user attributes branch from OLIOEX, prep for release
- Loading branch information
Showing
16 changed files
with
309 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
language: ruby | ||
rvm: | ||
- 2.2.5 | ||
- 2.3.1 | ||
- 2.6.7 | ||
- 2.7.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
module Urbanairship | ||
module Devices | ||
class Attributes | ||
|
||
SET = 'set' | ||
REMOVE = 'remove' | ||
|
||
def initialize(attributes) | ||
@attributes = attributes | ||
end | ||
|
||
def payload | ||
@payload ||= { attributes: attributes_list } | ||
end | ||
|
||
private | ||
|
||
def attributes_list | ||
@attributes.map{ |attribute| attribute_payload(attribute) } | ||
end | ||
|
||
def attribute_payload(attribute) | ||
if REMOVE == attribute[:action] | ||
remove_payload(attribute) | ||
else | ||
set_payload(attribute) | ||
end | ||
end | ||
|
||
def set_payload(attribute) | ||
{ | ||
action: SET, | ||
key: attribute[:key], | ||
value: attribute[:value], | ||
timestamp: (attribute[:timestamp] || timestamp).iso8601, | ||
} | ||
end | ||
|
||
def remove_payload(attribute) | ||
{ | ||
action: REMOVE, | ||
key: attribute[:key], | ||
timestamp: (attribute[:timestamp] || timestamp).iso8601, | ||
} | ||
end | ||
|
||
def timestamp | ||
@timestamp ||= Time.now.utc | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Urbanairship | ||
VERSION = '7.0.0' | ||
VERSION = '8.0.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
require 'spec_helper' | ||
require 'urbanairship' | ||
require 'urbanairship/devices/attributes' | ||
|
||
describe Urbanairship::Devices::Attributes do | ||
let(:key_1) { 'first_name' } | ||
let(:value_1) { 'Airship' } | ||
let(:key_2) { 'last_name' } | ||
let(:value_2) { 'API' } | ||
let(:timestamp) { Time.now.utc - 3600 } | ||
|
||
let(:attributes) do | ||
[ | ||
{ key: key_1, value: value_1, action: described_class::SET, timestamp: timestamp }, | ||
] | ||
end | ||
let(:expected) do | ||
{ | ||
attributes: [ | ||
{ | ||
key: key_1, | ||
value: value_1, | ||
action: described_class::SET, | ||
timestamp: timestamp.iso8601, | ||
}, | ||
], | ||
} | ||
end | ||
|
||
before { Timecop.freeze(Time.now.utc) } | ||
after { Timecop.return } | ||
|
||
describe 'Payload' do | ||
let(:payload) { described_class.new(attributes).payload } | ||
|
||
context 'Action type is not set' do | ||
let(:attributes) do | ||
[ | ||
{ key: key_1, value: value_1, timestamp: timestamp }, | ||
] | ||
end | ||
|
||
it 'defaults to `set` action' do | ||
puts timestamp.iso8601 | ||
expect(payload).to eq expected | ||
end | ||
end | ||
|
||
describe 'Set action' do | ||
it 'defaults to `set` action' do | ||
expect(payload).to eq expected | ||
end | ||
end | ||
|
||
context 'Timestamp not provided' do | ||
let(:timestamp) { nil } | ||
let(:expected) do | ||
{ | ||
attributes: [ | ||
{ | ||
key: key_1, | ||
value: value_1, | ||
action: described_class::SET, | ||
timestamp: Time.now.utc.iso8601, | ||
}, | ||
], | ||
} | ||
end | ||
|
||
it 'uses expected provided timestamp' do | ||
expect(payload).to eq expected | ||
end | ||
end | ||
|
||
describe 'Remove action' do | ||
let(:attributes) do | ||
[ | ||
{ key: key_1, action: described_class::REMOVE, timestamp: timestamp } | ||
] | ||
end | ||
let(:expected) do | ||
{ | ||
attributes: [ | ||
{ | ||
key: key_1, | ||
action: described_class::REMOVE, | ||
timestamp: timestamp.iso8601, | ||
}, | ||
], | ||
} | ||
end | ||
|
||
it 'generates expected payload' do | ||
expect(payload).to eq expected | ||
end | ||
end | ||
|
||
describe 'Loops over multiple records' do | ||
let(:attributes) do | ||
[ | ||
{ key: key_1, action: described_class::REMOVE }, | ||
{ key: key_2, value: value_2 } | ||
] | ||
end | ||
let(:expected) do | ||
{ | ||
attributes: [ | ||
{ | ||
key: key_1, | ||
action: described_class::REMOVE, | ||
timestamp: Time.now.utc.iso8601, | ||
}, | ||
{ | ||
key: key_2, | ||
value: value_2, | ||
action: described_class::SET, | ||
timestamp: Time.now.utc.iso8601, | ||
}, | ||
], | ||
} | ||
end | ||
|
||
it 'generates expected payload' do | ||
expect(payload).to eq expected | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.