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
Instance Method Summary collapse
- #analytics(start_date: nil, end_date: nil) ⇒ Object
-
#initialize(attributes, token) ⇒ 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, token) ⇒ 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, token @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 = 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, token end 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'], token rescue Error => e raise NotFoundError, e end |
Instance Method Details
#analytics(start_date: nil, end_date: nil) ⇒ Object
47 48 49 50 |
# File 'lib/patient_zero/source.rb', line 47 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
39 40 41 42 43 44 45 |
# File 'lib/patient_zero/source.rb', line 39 def parent if delete_id == id self else Source.find delete_id, token end end |
#platform_id ⇒ Object
31 32 33 |
# File 'lib/patient_zero/source.rb', line 31 def platform_id id.split('#').last end |
#social_type ⇒ Object
35 36 37 |
# File 'lib/patient_zero/source.rb', line 35 def id.scan(/\d+#(\w+)#\d+/).flatten.first end |