Class: PatientZero::Source
- Inherits:
-
Object
- Object
- PatientZero::Source
- Includes:
- Client
- Defined in:
- lib/patient_zero/source.rb
Instance Attribute Summary collapse
-
#delete_id ⇒ Object
Returns the value of attribute delete_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
- .all(token = Authorization.token) ⇒ Object
- .creation_url(platform, token = Authorization.token, reference_id = nil) ⇒ Object
- .find(source_id, token) ⇒ Object
Instance Method Summary collapse
- #analytics(start_date: nil, end_date: nil) ⇒ Object
-
#initialize(attributes) ⇒ Source
constructor
A new instance of Source.
- #parent ⇒ Object
- #platform_id ⇒ Object
- #social_type ⇒ Object
Methods included from Client
#connection, #get, included, #parse, #post, #put
Constructor Details
#initialize(attributes) ⇒ Source
Returns a new instance of Source.
7 8 9 10 11 12 13 14 15 |
# File 'lib/patient_zero/source.rb', line 7 def initialize attributes @id = attributes.fetch 'id' @name = attributes.fetch 'name' @invalid = attributes.fetch 'is_invalid' @tracked = attributes.fetch 'is_tracked' @platform = attributes.fetch 'platform' @delete_id = attributes.fetch 'delete_id' @token = attributes.fetch 'token' end |
Instance Attribute Details
#delete_id ⇒ Object
Returns the value of attribute delete_id.
5 6 7 |
# File 'lib/patient_zero/source.rb', line 5 def delete_id @delete_id end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/patient_zero/source.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/patient_zero/source.rb', line 5 def name @name end |
#platform ⇒ Object
Returns the value of attribute platform.
5 6 7 |
# File 'lib/patient_zero/source.rb', line 5 def platform @platform end |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/patient_zero/source.rb', line 5 def token @token end |
Class Method Details
.all(token = Authorization.token) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/patient_zero/source.rb', line 17 def self.all token=Authorization.token response = get '/mobile/api/v1/sources/', client_token: token response['sources'].map do |source_attributes| new source_attributes.merge('token' => token) end end |
.creation_url(platform, token = Authorization.token, reference_id = nil) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/patient_zero/source.rb', line 31 def self.creation_url platform, token=Authorization.token, reference_id=nil response = connection.get("/mobile/api/v1/sources/#{platform}/authenticate", client_token: token, reference_id: reference_id) creation_url = response.headers.fetch :location raise InvalidPlatformError, creation_url.split('error=').last if creation_url.include? 'error' creation_url end |
.find(source_id, token) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/patient_zero/source.rb', line 24 def self.find source_id, token response = get '/mobile/api/v1/sources/show/', id: source_id, client_token: token new response['source'].merge('token' => token) rescue Error => e raise NotFoundError, e end |
Instance Method Details
#analytics(start_date: nil, end_date: nil) ⇒ Object
54 55 56 57 |
# File 'lib/patient_zero/source.rb', line 54 def analytics start_date: nil, end_date: nil @analytics ||= {} @analytics["#{start_date}#{end_date}"] ||= Analytics.for_platform platform, token: token, source_id: id, start_date: start_date, end_date: end_date end |
#parent ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/patient_zero/source.rb', line 46 def parent if delete_id == id self else Source.find delete_id, token end end |
#platform_id ⇒ Object
38 39 40 |
# File 'lib/patient_zero/source.rb', line 38 def platform_id id.split('#').last end |
#social_type ⇒ Object
42 43 44 |
# File 'lib/patient_zero/source.rb', line 42 def id.scan(/\d+#(\w+)#\d+/).flatten.first end |