Class: Knievel::Client
- Inherits:
-
Object
- Object
- Knievel::Client
- Defined in:
- lib/knievel/client.rb
Overview
Convenience facade around the generated transport (‘Knievel::ApiClient` + `Knievel::Configuration`) and the hand-written `Knievel::Resources::*` wrappers.
Typical usage:
client = Knievel::Client.new(
host: "https://api.knievel-ads.example",
access_token: ENV.fetch("KNIEVEL_TOKEN"),
)
client.advertisers("pj_abc").each { |adv| puts adv.name }
client.advertisers("pj_abc").first(10)
client.advertisers("pj_abc").lazy.select(&:is_active).first(20)
client.advertisers("pj_abc").each_page { |page| process(page) }
Pass ‘page_size:` to a resource accessor to override the default 500-row page size:
client.advertisers("pj_abc", page_size: 50).each { ... }
Instance Attribute Summary collapse
-
#api_client ⇒ Object
readonly
Underlying generated transport.
Instance Method Summary collapse
- #ads(project_id, **opts) ⇒ Object
- #advertisers(project_id, **opts) ⇒ Object
- #campaigns(project_id, **opts) ⇒ Object
- #creative_templates(project_id, **opts) ⇒ Object
- #creatives(project_id, **opts) ⇒ Object
- #flights(project_id, **opts) ⇒ Object
-
#initialize(host: nil, access_token: nil) {|@config| ... } ⇒ Client
constructor
‘host` is the API base URL — accepts either a full URL (`api.knievel-ads.example`, `localhost:8080`) or a bare hostname.
- #sites(project_id, **opts) ⇒ Object
- #zones(project_id, **opts) ⇒ Object
Constructor Details
#initialize(host: nil, access_token: nil) {|@config| ... } ⇒ Client
‘host` is the API base URL — accepts either a full URL (`api.knievel-ads.example`, `localhost:8080`) or a bare hostname. The generated `Configuration#host=` setter strips the scheme silently, so we parse the URL ourselves to keep the scheme/port the caller intended. Falls back to the spec-stamped default (`localhost:8080`) when omitted — handy for local dev against compose.
‘access_token` is the bearer token. The `Configuration` block is a convenience for callers that need to twiddle other settings (timeouts, custom headers, etc.) before the underlying `ApiClient` materializes.
42 43 44 45 46 47 48 |
# File 'lib/knievel/client.rb', line 42 def initialize(host: nil, access_token: nil) @config = Knievel::Configuration.new apply_host(host) if host @config.access_token = access_token if access_token yield @config if block_given? @api_client = Knievel::ApiClient.new(@config) end |
Instance Attribute Details
#api_client ⇒ Object (readonly)
Underlying generated transport. Reach for this when you need the non-paginated endpoints (single ‘get_*`, `create_*`, `update_*`) — the hand-written wrappers only cover list operations.
68 69 70 |
# File 'lib/knievel/client.rb', line 68 def api_client @api_client end |
Instance Method Details
#ads(project_id, **opts) ⇒ Object
82 83 84 |
# File 'lib/knievel/client.rb', line 82 def ads(project_id, **opts) Resources::Ads.new(@api_client, project_id, **opts) end |
#advertisers(project_id, **opts) ⇒ Object
70 71 72 |
# File 'lib/knievel/client.rb', line 70 def advertisers(project_id, **opts) Resources::Advertisers.new(@api_client, project_id, **opts) end |
#campaigns(project_id, **opts) ⇒ Object
74 75 76 |
# File 'lib/knievel/client.rb', line 74 def campaigns(project_id, **opts) Resources::Campaigns.new(@api_client, project_id, **opts) end |
#creative_templates(project_id, **opts) ⇒ Object
90 91 92 |
# File 'lib/knievel/client.rb', line 90 def creative_templates(project_id, **opts) Resources::CreativeTemplates.new(@api_client, project_id, **opts) end |
#creatives(project_id, **opts) ⇒ Object
86 87 88 |
# File 'lib/knievel/client.rb', line 86 def creatives(project_id, **opts) Resources::Creatives.new(@api_client, project_id, **opts) end |
#flights(project_id, **opts) ⇒ Object
78 79 80 |
# File 'lib/knievel/client.rb', line 78 def flights(project_id, **opts) Resources::Flights.new(@api_client, project_id, **opts) end |