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.
- #property_show(property = nil) ⇒ Object
Constructor Details
#initialize(**options) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/wcc/blogs/client.rb', line 11 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 = [: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
48 49 50 51 52 53 54 55 |
# File 'lib/wcc/blogs/client.rb', line 48 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
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/wcc/blogs/client.rb', line 57 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
43 44 45 46 |
# File 'lib/wcc/blogs/client.rb', line 43 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.
27 28 29 30 31 32 33 |
# File 'lib/wcc/blogs/client.rb', line 27 def get(path, query = {}) url = URI.join(@base_url, path) Response.new(self, { url: url, query: query }, get_http(url, query)) end |
#property_show(property = nil) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/wcc/blogs/client.rb', line 35 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 |