Class: Cloudflare::API
Defined Under Namespace
Classes: Zone
Instance Method Summary collapse
-
#initialize(api_token) ⇒ API
constructor
A new instance of API.
- #zone_api(name) ⇒ Object
- #zone_id(name) ⇒ Object
Constructor Details
#initialize(api_token) ⇒ API
Returns a new instance of API.
25 26 27 28 29 30 31 32 33 |
# File 'lib/cloudflare/api.rb', line 25 def initialize(api_token) @options = { headers: { 'Authorization' => "Bearer #{api_token}", 'Content-Type' => 'application/json', 'Accept' => 'application/json', }, } end |
Instance Method Details
#zone_api(name) ⇒ Object
35 36 37 38 |
# File 'lib/cloudflare/api.rb', line 35 def zone_api(name) zone_id = zone_id(name) Zone.new(@options, zone_id) end |
#zone_id(name) ⇒ Object
40 41 42 43 44 |
# File 'lib/cloudflare/api.rb', line 40 def zone_id(name) zones = self.class.get('/zones', @options.merge(query: { name: name })).parsed_response raise "#{name} not found" if zones.empty? zones.first['id'] end |