Class: WCC::Blogs::Client
- Inherits:
-
Object
- Object
- WCC::Blogs::Client
- Defined in:
- lib/wcc/blogs/client/response.rb,
lib/wcc/blogs/client.rb
Defined Under Namespace
Classes: ApiError, NotFoundError, Response
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#default_property ⇒ Object
readonly
Returns the value of attribute default_property.
Instance Method Summary collapse
- #blog_list(property: nil, year: nil) ⇒ Object
- #blog_show(slug, digest: nil) ⇒ Object
- #collection_show(key) ⇒ Object
-
#get(path, query = {}) ⇒ Object
performs an HTTP GET request to the specified path within the configured space and environment.
-
#initialize(**options) ⇒ Client
constructor
A new instance of Client.
- #options ⇒ Object
- #property_show(property = nil) ⇒ Object
Constructor Details
#initialize(**options) ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/wcc/blogs/client.rb', line 20 def initialize(**) if [:publishing_target] raise ArgumentError, 'publishing_target has been renamed to default_property' end @default_property = [:default_property] base_url = URI.parse([:base_url] || 'https://di0v2frwtdqnv.cloudfront.net') @base_path = base_url.path == '' ? '/api/v1' : base_url.path @base_url = base_url.to_s @connection = [:connection] || default_connection @query_defaults = .slice(:preview) @query_defaults[:preview] = 'devslikepizza' if [:preview] == true @query_defaults.merge!([:query_defaults] || {}) end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
9 10 11 |
# File 'lib/wcc/blogs/client.rb', line 9 def base_path @base_path end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
9 10 11 |
# File 'lib/wcc/blogs/client.rb', line 9 def base_url @base_url end |
#default_property ⇒ Object (readonly)
Returns the value of attribute default_property.
9 10 11 |
# File 'lib/wcc/blogs/client.rb', line 9 def default_property @default_property end |
Instance Method Details
#blog_list(property: nil, year: nil) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/wcc/blogs/client.rb', line 59 def blog_list(property: nil, year: nil) property ||= default_property raise ArgumentError, 'No Property given' unless property path = base_path + '/property/' + property + '/blog' path += '/' + year if year get(path).assert_ok! end |
#blog_show(slug, digest: nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/wcc/blogs/client.rb', line 68 def blog_show(slug, digest: nil) path = base_path + '/blog/' + slug.sub(%r{^/}, '') path += '/' + digest + '.json' if digest get(path).tap do |resp| resp.assert_ok! check_default_property(resp) end rescue WCC::Blogs::Client::NotFoundError => e raise WCC::Blogs::NotFoundException, e. end |
#collection_show(key) ⇒ Object
54 55 56 57 |
# File 'lib/wcc/blogs/client.rb', line 54 def collection_show(key) path = base_path + '/collection/' + key get(path).assert_ok! end |
#get(path, query = {}) ⇒ Object
performs an HTTP GET request to the specified path within the configured space and environment. Query parameters are merged with the defaults and appended to the request.
38 39 40 41 42 43 44 |
# File 'lib/wcc/blogs/client.rb', line 38 def get(path, query = {}) url = URI.join(@base_url, path) Response.new(self, { url: url, query: query }, get_http(url, query)) end |
#options ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/wcc/blogs/client.rb', line 11 def { default_property: @default_property, base_url: @base_url, connection: @connection, query_defaults: @query_defaults } end |
#property_show(property = nil) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/wcc/blogs/client.rb', line 46 def property_show(property = nil) property ||= default_property raise ArgumentError, 'No Property given' unless property path = base_path + '/property/' + property get(path).assert_ok! end |