Class: Stripe::TestHelpers::TestClock

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List
Includes:
APIOperations::Delete
Defined in:
lib/stripe/resources/test_helpers/test_clock.rb

Overview

A test clock enables deterministic control over objects in testmode. With a test clock, you can create objects at a frozen time in the past or future, and advance to a specific future time to observe webhooks and state changes. After the clock advances, you can either validate the current state of your scenario (and test your assumptions), change the current state of your scenario (and test more complex scenarios), or keep advancing forward in time.

Defined Under Namespace

Classes: AdvanceParams, CreateParams, DeleteParams, ListParams, StatusDetails

Constant Summary collapse

OBJECT_NAME =
"test_helpers.test_clock"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary collapse

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::Delete

included

Methods inherited from APIResource

class_name, custom_method, #refresh, #request_stripe_object, resource_url, #resource_url, retrieve, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values

Constructor Details

This class inherits a constructor from Stripe::StripeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject

Instance Attribute Details

#createdObject (readonly)

Time at which the object was created. Measured in seconds since the Unix epoch.



76
77
78
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 76

def created
  @created
end

#deletedObject (readonly)

Always true for a deleted object



94
95
96
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 94

def deleted
  @deleted
end

#deletes_afterObject (readonly)

Time at which this clock is scheduled to auto delete.



78
79
80
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 78

def deletes_after
  @deletes_after
end

#frozen_timeObject (readonly)

Time at which all objects belonging to this clock are frozen.



80
81
82
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 80

def frozen_time
  @frozen_time
end

#idObject (readonly)

Unique identifier for the object.



82
83
84
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 82

def id
  @id
end

#livemodeObject (readonly)

Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.



84
85
86
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 84

def livemode
  @livemode
end

#nameObject (readonly)

The custom name supplied at creation.



86
87
88
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 86

def name
  @name
end

#objectObject (readonly)

String representing the object’s type. Objects of the same type share the same value.



88
89
90
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 88

def object
  @object
end

#statusObject (readonly)

The status of the Test Clock.



90
91
92
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 90

def status
  @status
end

#status_detailsObject (readonly)

Attribute for field status_details



92
93
94
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 92

def status_details
  @status_details
end

Class Method Details

.advance(test_clock, params = {}, opts = {}) ⇒ Object

Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.



107
108
109
110
111
112
113
114
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 107

def self.advance(test_clock, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/test_helpers/test_clocks/%<test_clock>s/advance", { test_clock: CGI.escape(test_clock) }),
    params: params,
    opts: opts
  )
end

.create(params = {}, opts = {}) ⇒ Object

Creates a new test clock that can be attached to new customers and quotes.



117
118
119
120
121
122
123
124
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 117

def self.create(params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: "/v1/test_helpers/test_clocks",
    params: params,
    opts: opts
  )
end

.delete(test_clock, params = {}, opts = {}) ⇒ Object

Deletes a test clock.



127
128
129
130
131
132
133
134
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 127

def self.delete(test_clock, params = {}, opts = {})
  request_stripe_object(
    method: :delete,
    path: format("/v1/test_helpers/test_clocks/%<test_clock>s", { test_clock: CGI.escape(test_clock) }),
    params: params,
    opts: opts
  )
end

.list(params = {}, opts = {}) ⇒ Object

Returns a list of your test clocks.



147
148
149
150
151
152
153
154
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 147

def self.list(params = {}, opts = {})
  request_stripe_object(
    method: :get,
    path: "/v1/test_helpers/test_clocks",
    params: params,
    opts: opts
  )
end

.object_nameObject



15
16
17
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 15

def self.object_name
  "test_helpers.test_clock"
end

Instance Method Details

#advance(params = {}, opts = {}) ⇒ Object

Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.



97
98
99
100
101
102
103
104
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 97

def advance(params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/test_helpers/test_clocks/%<test_clock>s/advance", { test_clock: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end

#delete(params = {}, opts = {}) ⇒ Object

Deletes a test clock.



137
138
139
140
141
142
143
144
# File 'lib/stripe/resources/test_helpers/test_clock.rb', line 137

def delete(params = {}, opts = {})
  request_stripe_object(
    method: :delete,
    path: format("/v1/test_helpers/test_clocks/%<test_clock>s", { test_clock: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end