Class: Shutterstock::Subscription

Inherits:
Driver
  • Object
show all
Defined in:
lib/client/subscription.rb

Constant Summary

Constants inherited from Driver

Driver::TRUTHY_JSON_VALUES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Driver

api, client, #client, #json_true?, #methods, #respond_to, #to_date

Constructor Details

#initialize(params = {}) ⇒ Subscription

Returns a new instance of Subscription.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/client/subscription.rb', line 9

def initialize(params={})
	@hash                   = params
    @id                     = params["id"]                                                          # (string),
    @description            = params["description"] if params["description"]                        # (string, optional),
    @expiration_time        = to_date params["expiration_time"] if params["expiration_time"]        # (string, optional),
    @price_per_download     = SubscriptionPrice.new(params["price_per_download"]) if params["price_per_download"]     # (Price, optional),
    @license                = params["license"] if params["license"]                                # (string, optional),
    @allotment              = SubscriptionAllotment.new(params["allotment"]) if params["allotment"] # (Allotment, optional),
    @formats                = SubscriptionLicenseFormats.new(params["formats"]) if params["formats"] # (LicenseFormat[], optional),
    @metadata               = params["metadata"] if params["metadata"]                              # (SubscriptionMetadata, optional)
end

Instance Attribute Details

#allotmentObject (readonly)

Returns the value of attribute allotment.



5
6
7
# File 'lib/client/subscription.rb', line 5

def allotment
  @allotment
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/client/subscription.rb', line 5

def description
  @description
end

#expiration_timeObject (readonly)

Returns the value of attribute expiration_time.



5
6
7
# File 'lib/client/subscription.rb', line 5

def expiration_time
  @expiration_time
end

#formatsObject (readonly)

Returns the value of attribute formats.



5
6
7
# File 'lib/client/subscription.rb', line 5

def formats
  @formats
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/client/subscription.rb', line 5

def id
  @id
end

#licenseObject (readonly)

Returns the value of attribute license.



5
6
7
# File 'lib/client/subscription.rb', line 5

def license
  @license
end

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'lib/client/subscription.rb', line 5

def 
  @metadata
end

#price_per_downloadObject (readonly)

Returns the value of attribute price_per_download.



5
6
7
# File 'lib/client/subscription.rb', line 5

def price_per_download
  @price_per_download
end

Instance Method Details

#allows_image_size_download?(size) ⇒ Boolean

True if this subscription can handle the size passed eg “small”

Returns:

  • (Boolean)


26
27
28
# File 'lib/client/subscription.rb', line 26

def allows_image_size_download?(size)
  !!(!expired? && formats.find {|format| format.size == size})
end

#expired?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/client/subscription.rb', line 21

def expired?
  @expiration_time<DateTime.now
end

#has_downloads_left?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/client/subscription.rb', line 30

def has_downloads_left?
  allotment && allotment.has_downloads_left?
end