actv 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +30 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +64 -0
- data/Gemfile +4 -0
- data/Guardfile +20 -0
- data/LICENSE +22 -0
- data/README.md +63 -0
- data/Rakefile +17 -0
- data/actv.gemspec +34 -0
- data/lib/actv.rb +48 -0
- data/lib/actv/address.rb +9 -0
- data/lib/actv/article.rb +89 -0
- data/lib/actv/article_search_results.rb +15 -0
- data/lib/actv/asset.rb +186 -0
- data/lib/actv/asset_channel.rb +13 -0
- data/lib/actv/asset_component.rb +8 -0
- data/lib/actv/asset_description.rb +15 -0
- data/lib/actv/asset_description_type.rb +12 -0
- data/lib/actv/asset_image.rb +13 -0
- data/lib/actv/asset_legacy_data.rb +20 -0
- data/lib/actv/asset_price.rb +11 -0
- data/lib/actv/asset_seo_url.rb +5 -0
- data/lib/actv/asset_status.rb +17 -0
- data/lib/actv/asset_tag.rb +9 -0
- data/lib/actv/asset_topic.rb +11 -0
- data/lib/actv/base.rb +148 -0
- data/lib/actv/channel.rb +13 -0
- data/lib/actv/client.rb +330 -0
- data/lib/actv/configurable.rb +39 -0
- data/lib/actv/default.rb +87 -0
- data/lib/actv/error.rb +32 -0
- data/lib/actv/error/bad_gateway.rb +11 -0
- data/lib/actv/error/bad_request.rb +10 -0
- data/lib/actv/error/client_error.rb +39 -0
- data/lib/actv/error/enhance_your_calm.rb +10 -0
- data/lib/actv/error/forbidden.rb +10 -0
- data/lib/actv/error/internal_server_error.rb +11 -0
- data/lib/actv/error/not_acceptable.rb +10 -0
- data/lib/actv/error/not_found.rb +10 -0
- data/lib/actv/error/server_error.rb +19 -0
- data/lib/actv/error/service_unavailable.rb +11 -0
- data/lib/actv/error/unauthorized.rb +10 -0
- data/lib/actv/event.rb +213 -0
- data/lib/actv/event_result.rb +8 -0
- data/lib/actv/event_search_results.rb +11 -0
- data/lib/actv/evergreen.rb +53 -0
- data/lib/actv/facet.rb +16 -0
- data/lib/actv/facet_term.rb +5 -0
- data/lib/actv/facet_value.rb +7 -0
- data/lib/actv/identity.rb +28 -0
- data/lib/actv/interest.rb +39 -0
- data/lib/actv/null_object.rb +19 -0
- data/lib/actv/phone_number.rb +9 -0
- data/lib/actv/place.rb +24 -0
- data/lib/actv/popular_interest.rb +18 -0
- data/lib/actv/popular_interest_search_results.rb +12 -0
- data/lib/actv/request/multipart_with_file.rb +37 -0
- data/lib/actv/response/parse_json.rb +29 -0
- data/lib/actv/response/raise_client_error.rb +21 -0
- data/lib/actv/response/raise_server_error.rb +18 -0
- data/lib/actv/search_results.rb +30 -0
- data/lib/actv/sub_event.rb +15 -0
- data/lib/actv/tag.rb +9 -0
- data/lib/actv/topic.rb +9 -0
- data/lib/actv/user.rb +38 -0
- data/lib/actv/version.rb +3 -0
- data/spec/actv/article_search_results_spec.rb +16 -0
- data/spec/actv/article_spec.rb +44 -0
- data/spec/actv/asset_channel_spec.rb +17 -0
- data/spec/actv/asset_description_spec.rb +17 -0
- data/spec/actv/asset_image_spec.rb +27 -0
- data/spec/actv/asset_price_spec.rb +23 -0
- data/spec/actv/asset_spec.rb +172 -0
- data/spec/actv/asset_status_spec.rb +24 -0
- data/spec/actv/base_spec.rb +51 -0
- data/spec/actv/client/articles_spec.rb +130 -0
- data/spec/actv/client/assets_spec.rb +87 -0
- data/spec/actv/client/event_results_spec.rb +35 -0
- data/spec/actv/client/events_spec.rb +99 -0
- data/spec/actv/client/search_spec.rb +58 -0
- data/spec/actv/client/system_health_spec.rb +16 -0
- data/spec/actv/client/users_spec.rb +31 -0
- data/spec/actv/client_spec.rb +140 -0
- data/spec/actv/event_spec.rb +331 -0
- data/spec/actv/evergreen_spec.rb +33 -0
- data/spec/actv/identifiable_spec.rb +31 -0
- data/spec/actv/null_object_spec.rb +24 -0
- data/spec/actv/place_spec.rb +25 -0
- data/spec/actv/search_results_spec.rb +44 -0
- data/spec/actv/user_spec.rb +25 -0
- data/spec/actv_spec.rb +60 -0
- data/spec/faraday/response_spec.rb +0 -0
- data/spec/fixtures/me.json +21 -0
- data/spec/fixtures/system_health.json +1 -0
- data/spec/fixtures/valid_article.json +187 -0
- data/spec/fixtures/valid_asset.json +185 -0
- data/spec/fixtures/valid_event.json +188 -0
- data/spec/fixtures/valid_event_results.json +23 -0
- data/spec/fixtures/valid_evergreen.json +1 -0
- data/spec/fixtures/valid_evergreen_child_1.json +1 -0
- data/spec/fixtures/valid_search.json +1282 -0
- data/spec/fixtures/valid_search_no_event_results.json +5 -0
- data/spec/fixtures/valid_search_no_results.json +9 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/helper.rb +43 -0
- metadata +432 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'actv/asset_description_type'
|
|
2
|
+
|
|
3
|
+
module ACTV
|
|
4
|
+
class AssetDescription < Base
|
|
5
|
+
|
|
6
|
+
attr_reader :description
|
|
7
|
+
|
|
8
|
+
def type
|
|
9
|
+
@description_type ||= ACTV::AssetDescriptionType.new(@attrs[:descriptionType]) unless @attrs[:descriptionType].nil?
|
|
10
|
+
end
|
|
11
|
+
alias description_type type
|
|
12
|
+
alias descriptionType type
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module ACTV
|
|
2
|
+
class AssetImage < Base
|
|
3
|
+
|
|
4
|
+
attr_reader :imageUrlAdr, :imageName, :imageCaptionTxt, :linkUrl, :linkTarget
|
|
5
|
+
|
|
6
|
+
alias url imageUrlAdr
|
|
7
|
+
alias name imageName
|
|
8
|
+
alias caption imageCaptionTxt
|
|
9
|
+
alias link linkUrl
|
|
10
|
+
alias target linkTarget
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'actv/identity'
|
|
2
|
+
|
|
3
|
+
module ACTV
|
|
4
|
+
class AssetLegacyData < Base
|
|
5
|
+
|
|
6
|
+
attr_reader :assetTypeId, :typeName, :onlineRegistration, :seoUrl,
|
|
7
|
+
:substitutionUrl, :isSearchable, :createdDate, :modifiedDate
|
|
8
|
+
|
|
9
|
+
alias id assetTypeId
|
|
10
|
+
alias type_name typeName
|
|
11
|
+
alias online_registration? onlineRegistration
|
|
12
|
+
alias online_registration onlineRegistration
|
|
13
|
+
alias seo_url seoUrl
|
|
14
|
+
alias substitution_url substitutionUrl
|
|
15
|
+
alias is_searchable? isSearchable
|
|
16
|
+
alias created_at createdDate
|
|
17
|
+
alias updated_at modifiedDate
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'actv/identity'
|
|
2
|
+
|
|
3
|
+
module ACTV
|
|
4
|
+
class AssetStatus < ACTV::Identity
|
|
5
|
+
|
|
6
|
+
attr_reader :assetStatusId, :assetStatusName, :isSearchable, :isDeleted,
|
|
7
|
+
:createdDate, :modifiedDate
|
|
8
|
+
|
|
9
|
+
alias id assetStatusId
|
|
10
|
+
alias name assetStatusName
|
|
11
|
+
alias is_searchable? isSearchable
|
|
12
|
+
alias is_deleted? isDeleted
|
|
13
|
+
alias created_at createdDate
|
|
14
|
+
alias updated_at modifiedDate
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/actv/base.rb
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
require 'forwardable'
|
|
2
|
+
require 'actv/null_object'
|
|
3
|
+
require 'uri'
|
|
4
|
+
|
|
5
|
+
module ACTV
|
|
6
|
+
class Base
|
|
7
|
+
extend Forwardable
|
|
8
|
+
attr_reader :attrs
|
|
9
|
+
alias body attrs
|
|
10
|
+
def_delegators :attrs, :delete, :update
|
|
11
|
+
|
|
12
|
+
# Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
|
|
13
|
+
#
|
|
14
|
+
# @overload self. attr_reader(attr)
|
|
15
|
+
# @param attr [Symbol]
|
|
16
|
+
# @overload self. attr_reader(attrs)
|
|
17
|
+
# @param attrs [Array<Symbol>]
|
|
18
|
+
def self.attr_reader(*attrs)
|
|
19
|
+
attrs.each do |attribute|
|
|
20
|
+
define_attribute_method(attribute)
|
|
21
|
+
define_predicate_method(attribute)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.object_attr_reader(klass, key1, key2=nil)
|
|
26
|
+
define_attribute_method(key1, kass, key2)
|
|
27
|
+
define_predicate_method(key1)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.uri_attr_reader(*attrs)
|
|
31
|
+
attrs.each do |uri_key|
|
|
32
|
+
array = uri_key.to_s.split("_")
|
|
33
|
+
index = array.index("uri")
|
|
34
|
+
array[index] = "url"
|
|
35
|
+
url_key = array.join("_").to_sym
|
|
36
|
+
define_uri_method(uri_key, url_key)
|
|
37
|
+
define_predicate_method(uri_key, url_key)
|
|
38
|
+
|
|
39
|
+
alias_method(url_key, uri_key)
|
|
40
|
+
alias_method("#{url_key}?", "#{uri_key}?")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.define_uri_method(key1, key2)
|
|
45
|
+
define_method(key1) do
|
|
46
|
+
memoize(key1) do
|
|
47
|
+
::URI.parse(@attrs[key2]) if @attrs[key2]
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.define_attribute_method(key1, klass=nil, key2=nil)
|
|
53
|
+
define_method(key1) do
|
|
54
|
+
memoize(key1) do
|
|
55
|
+
if klass.nil?
|
|
56
|
+
@attrs[key1]
|
|
57
|
+
else
|
|
58
|
+
if @attrs[key1]
|
|
59
|
+
if key2.nil?
|
|
60
|
+
ACTV.const_get(klass).new(@attrs[key1])
|
|
61
|
+
else
|
|
62
|
+
attrs = @attrs.dup
|
|
63
|
+
value = attrs.delete(key1)
|
|
64
|
+
ACTV.const_get(klass).new(value.update(key2 => attrs))
|
|
65
|
+
end
|
|
66
|
+
else
|
|
67
|
+
ACTV::NullObject.instance
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.define_predicate_method(key1, key2=key1)
|
|
75
|
+
define_method(:"#{key1}?") do
|
|
76
|
+
!!@attrs[key2]
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def self.from_response(response={})
|
|
81
|
+
new(response[:body])
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def initialize(attrs={})
|
|
85
|
+
@attrs = attrs || {}
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def [](method)
|
|
89
|
+
send(method)
|
|
90
|
+
rescue NoMethodError
|
|
91
|
+
nil
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def memoize(key, &block)
|
|
95
|
+
ivar = :"@#{key}"
|
|
96
|
+
return instance_variable_get(ivar) if instance_variable_defined?(ivar)
|
|
97
|
+
result = block.call
|
|
98
|
+
instance_variable_set(ivar, result)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def method_missing(meth, *args, &block)
|
|
102
|
+
if @attrs && @attrs.has_key?(meth)
|
|
103
|
+
@attrs[meth]
|
|
104
|
+
elsif meth.to_s.include?('=') and !args.empty?
|
|
105
|
+
@attrs[meth[0..-2].to_sym] = args.first
|
|
106
|
+
else
|
|
107
|
+
super
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def respond_to?(meth, *args)
|
|
112
|
+
if @attrs && @attrs.has_key?(meth)
|
|
113
|
+
true
|
|
114
|
+
else
|
|
115
|
+
super
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Creation of object hash when sending request to soap
|
|
120
|
+
def to_hash
|
|
121
|
+
hash = {}
|
|
122
|
+
hash["attrs"] = @attrs
|
|
123
|
+
|
|
124
|
+
self.instance_variables.keep_if { |key| key != :@attrs }.each do |var|
|
|
125
|
+
val = self.instance_variable_get(var)
|
|
126
|
+
hash["attrs"][var.to_s.delete("@").to_sym] = val.to_hash if val.is_a? ACTV::Base
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
hash["attrs"]
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
protected
|
|
133
|
+
|
|
134
|
+
# @param attr [Symbol]
|
|
135
|
+
# @param other [ACTV::Base]
|
|
136
|
+
# @return [Boolean]
|
|
137
|
+
def attr_equal(attr, other)
|
|
138
|
+
self.class == other.class && !other.send(attr).nil? && send(attr) == other.send(attr)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# @param other [ACTV::Base]
|
|
142
|
+
# @return [Boolean]
|
|
143
|
+
def attrs_equal(other)
|
|
144
|
+
self.class == other.class && !other.attrs.empty? && attrs == other.attrs
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
end
|
|
148
|
+
end
|
data/lib/actv/channel.rb
ADDED
data/lib/actv/client.rb
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
require 'faraday'
|
|
2
|
+
require 'actv/article'
|
|
3
|
+
require 'actv/article_search_results'
|
|
4
|
+
require 'actv/asset'
|
|
5
|
+
require 'actv/configurable'
|
|
6
|
+
require 'actv/error/forbidden'
|
|
7
|
+
require 'actv/error/not_found'
|
|
8
|
+
require 'actv/event'
|
|
9
|
+
require 'actv/event_result'
|
|
10
|
+
require 'actv/evergreen'
|
|
11
|
+
require 'actv/sub_event'
|
|
12
|
+
require 'actv/search_results'
|
|
13
|
+
require 'actv/event_search_results'
|
|
14
|
+
require 'actv/popular_interest_search_results'
|
|
15
|
+
require 'actv/user'
|
|
16
|
+
require 'simple_oauth'
|
|
17
|
+
|
|
18
|
+
module ACTV
|
|
19
|
+
# Wrapper for the ACTV REST API
|
|
20
|
+
#
|
|
21
|
+
# @note
|
|
22
|
+
class Client
|
|
23
|
+
include ACTV::Configurable
|
|
24
|
+
|
|
25
|
+
attr_reader :oauth_token
|
|
26
|
+
|
|
27
|
+
# Initialized a new Client object
|
|
28
|
+
#
|
|
29
|
+
# @param options [Hash]
|
|
30
|
+
# @return[ACTV::Client]
|
|
31
|
+
def initialize(options={})
|
|
32
|
+
ACTV::Configurable.keys.each do |key|
|
|
33
|
+
instance_variable_set("@#{key}", options[key] || ACTV.options[key])
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Returns assets that match a specified query.
|
|
38
|
+
#
|
|
39
|
+
# @authentication_required No
|
|
40
|
+
# @param q [String] A search term.
|
|
41
|
+
# @param options [Hash] A customizable set of options.
|
|
42
|
+
# @return [ACTV::SearchResults] Return assets that match a specified query with search metadata
|
|
43
|
+
# @example Returns assets related to running
|
|
44
|
+
# ACTV.assets('running')
|
|
45
|
+
# ACTV.search('running')
|
|
46
|
+
def assets(q, params={})
|
|
47
|
+
response = get("/v2/search.json", params.merge(query: q))
|
|
48
|
+
ACTV::SearchResults.from_response(response)
|
|
49
|
+
end
|
|
50
|
+
alias search assets
|
|
51
|
+
|
|
52
|
+
# Returns an asset with the specified ID in an array
|
|
53
|
+
#
|
|
54
|
+
# @authentication_required No
|
|
55
|
+
# @return [ACTV::Asset] The requested asset.
|
|
56
|
+
# @param id [String] An assset ID.
|
|
57
|
+
# @param options [Hash] A customizable set of options.
|
|
58
|
+
# @example Return the asset with the id BA288960-2718-4B20-B380-8F939596B123
|
|
59
|
+
# ACTV.asset("BA288960-2718-4B20-B380-8F939596B123")
|
|
60
|
+
def asset(id, params={})
|
|
61
|
+
response = get("/v2/assets/#{id}.json", params)
|
|
62
|
+
|
|
63
|
+
if response[:body].is_a? Array
|
|
64
|
+
results = []
|
|
65
|
+
response[:body].each do |item|
|
|
66
|
+
results << ACTV::Asset.from_response({body: item})
|
|
67
|
+
end
|
|
68
|
+
results
|
|
69
|
+
else
|
|
70
|
+
[ACTV::Asset.from_response(response)]
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Returns an asset with the specified url path
|
|
75
|
+
#
|
|
76
|
+
# @authentication_required No
|
|
77
|
+
# @return [ACTV::Asset] The requested asset
|
|
78
|
+
# @param path [String]
|
|
79
|
+
# @example Return an asset with the url http://www.active.com/miami-fl/running/miami-marathon-and-half-marathon-2014
|
|
80
|
+
# ACTV.asset_by_path("http://www.active.com/miami-fl/running/miami-marathon-and-half-marathon-2014")
|
|
81
|
+
def find_asset_by_url(url)
|
|
82
|
+
url_md5 = Digest::MD5.hexdigest(url)
|
|
83
|
+
response = get("/v2/seourls/#{url_md5}?load_asset=true")
|
|
84
|
+
|
|
85
|
+
ACTV::Asset.from_response(response)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Returns articles that match a specified query.
|
|
89
|
+
#
|
|
90
|
+
# @authentication_required No
|
|
91
|
+
# @param q [String] A search term.
|
|
92
|
+
# @param options [Hash] A customizable set of options.
|
|
93
|
+
# @return [ACTV::SearchResults] Return articles that match a specified query with search metadata
|
|
94
|
+
# @example Returns articles related to running
|
|
95
|
+
# ACTV.articles('running')
|
|
96
|
+
# ACTV.articles('running')
|
|
97
|
+
def articles(q, params={})
|
|
98
|
+
response = get("/v2/search.json", params.merge({query: q, category: 'articles'}))
|
|
99
|
+
ACTV::ArticleSearchResults.from_response(response)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Returns an article with the specified ID
|
|
103
|
+
#
|
|
104
|
+
# @authentication_required No
|
|
105
|
+
# @return [ACTV::Article] The requested article.
|
|
106
|
+
# @param id [String] An article ID.
|
|
107
|
+
# @param options [Hash] A customizable set of options.
|
|
108
|
+
# @example Return the article with the id BA288960-2718-4B20-B380-8F939596B123
|
|
109
|
+
# ACTV.article("BA288960-2718-4B20-B380-8F939596B123")
|
|
110
|
+
def article(id)
|
|
111
|
+
response = get("/v2/assets/#{id}.json")
|
|
112
|
+
article = ACTV::Article.from_response(response)
|
|
113
|
+
article.is_article? ? article : nil
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def events(q, params={})
|
|
117
|
+
response = get("/v2/search.json", params.merge({query: q, category: 'event'}))
|
|
118
|
+
ACTV::EventSearchResults.from_response(response)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def event(id)
|
|
122
|
+
response = get("/v2/assets/#{id}.json")
|
|
123
|
+
event = ACTV::Event.from_response(response)
|
|
124
|
+
event = ACTV::Evergreen.new(event) if event.evergreen?
|
|
125
|
+
event.is_article? ? nil : event
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Returns popular assets that match a specified query.
|
|
129
|
+
#
|
|
130
|
+
# @authentication_required No
|
|
131
|
+
# @param options [Hash] A customizable set of options.
|
|
132
|
+
# @return [ACTV::SearchResults] Return events that match a specified query with search metadata
|
|
133
|
+
# @example Returns articles related to running
|
|
134
|
+
# ACTV.popular_events()
|
|
135
|
+
# ACTV.popular_events("topic:running")
|
|
136
|
+
def popular_events(params={})
|
|
137
|
+
response = get("/v2/events/popular", params)
|
|
138
|
+
ACTV::SearchResults.from_response(response)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Returns upcoming assets that match a specified query.
|
|
142
|
+
#
|
|
143
|
+
# @authentication_required No
|
|
144
|
+
# @param options [Hash] A customizable set of options.
|
|
145
|
+
# @return [ACTV::SearchResults] Return events that match a specified query with search metadata
|
|
146
|
+
# @example Returns articles related to running
|
|
147
|
+
# ACTV.upcoming_events()
|
|
148
|
+
# ACTV.upcoming_events("topic:running")
|
|
149
|
+
def upcoming_events(params={})
|
|
150
|
+
response = get("/v2/events/upcoming", params)
|
|
151
|
+
ACTV::SearchResults.from_response(response)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# Returns popular assets that match a specified query.
|
|
155
|
+
#
|
|
156
|
+
# @authentication_required No
|
|
157
|
+
# @param options [Hash] A customizable set of options.
|
|
158
|
+
# @return [ACTV::SearchResults] Return events that match a specified query with search metadata
|
|
159
|
+
# @example Returns articles related to running
|
|
160
|
+
# ACTV.popular_articles()
|
|
161
|
+
# ACTV.popular_articles("topic:running")
|
|
162
|
+
def popular_articles(params={})
|
|
163
|
+
response = get("/v2/articles/popular", params)
|
|
164
|
+
ACTV::ArticleSearchResults.from_response(response)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Returns popular interests
|
|
168
|
+
#
|
|
169
|
+
# @authentication_required No
|
|
170
|
+
# @param options [Hash] A customizable set of options.
|
|
171
|
+
# @return [ACTV::PopularInterestSearchResults] Return intersts
|
|
172
|
+
# @example Returns most popular interests
|
|
173
|
+
# ACTV.popular_interests()
|
|
174
|
+
# ACTV.popular_interests({per_page: 8})
|
|
175
|
+
def popular_interests(params={}, options={})
|
|
176
|
+
response = get("/interest/_search", params, options)
|
|
177
|
+
ACTV::PopularInterestSearchResults.from_response(response)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Returns popular searches
|
|
181
|
+
#
|
|
182
|
+
# @authentication_required No
|
|
183
|
+
# @param options [Hash] A customizable set of options.
|
|
184
|
+
# @return [ACTV::PopularSearchSearchResults] Return searches
|
|
185
|
+
# @example Returns most popular searches
|
|
186
|
+
# ACTV.popular_searches()
|
|
187
|
+
# ACTV.popular_searches({per_page: 8})
|
|
188
|
+
def popular_searches(options={})
|
|
189
|
+
#response = get("/v2/articles/popular", params)
|
|
190
|
+
#ACTV::ArticleSearchResults.from_response(response)
|
|
191
|
+
["Couch to 5k","Kids' Camps","Swimming Classes","Half Marathons in Southern CA","Gyms in Solana Beach","Dignissim Qui Blandit","Dolore Te Feugait","Lorem Ipsum","Convnetio Ibidem","Aliquam Jugis"]
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Returns a result with the specified asset ID and asset type ID
|
|
195
|
+
#
|
|
196
|
+
# @authentication_required No
|
|
197
|
+
# @return [ACTV::EventResult] The requested event result.
|
|
198
|
+
# @param assetId [String] An asset ID.
|
|
199
|
+
# @param assetTypeId [String] An asset type ID.
|
|
200
|
+
# @example Return the result with the assetId 286F5731-9800-4C6E-ADD5-0E3B72392CA7 and assetTypeId 3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6
|
|
201
|
+
# ACTV.event_results("286F5731-9800-4C6E-ADD5-0E3B72392CA7","3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6")
|
|
202
|
+
def event_results(assetId, assetTypeId, options={})
|
|
203
|
+
begin
|
|
204
|
+
response = get("/api/v1/events/#{assetId}/#{assetTypeId}.json", {}, options)
|
|
205
|
+
ACTV::EventResult.from_response(response)
|
|
206
|
+
rescue
|
|
207
|
+
nil
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# Returns the currently logged in user
|
|
212
|
+
#
|
|
213
|
+
# @authentication_required Yes
|
|
214
|
+
# @return [ACTV::User] The requested current user.
|
|
215
|
+
# @param options [Hash] A customizable set of options.
|
|
216
|
+
# @example Return current_user if authentication was susccessful
|
|
217
|
+
# ACTV.me
|
|
218
|
+
def me(params={})
|
|
219
|
+
response = get("/v2/me.json", params)
|
|
220
|
+
user = ACTV::User.from_response(response)
|
|
221
|
+
user.access_token = @oauth_token
|
|
222
|
+
user
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def update_me(user, params={})
|
|
226
|
+
response = put("/v2/me.json", params.merge(user))
|
|
227
|
+
user = ACTV::User.from_response(response)
|
|
228
|
+
user.access_token = @oauth_token
|
|
229
|
+
user
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def user_name_exists?(user_name, params={})
|
|
233
|
+
get("/v2/users/user_name/#{user_name}", params)[:body][:exists]
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def display_name_exists?(display_name, params={})
|
|
237
|
+
get("/v2/users/display_name/#{URI.escape(display_name)}", params)[:body][:exists]
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def is_advantage_member?(options={})
|
|
241
|
+
get("/v2/me/is_advantage_member", options)[:body][:is_advantage_member]
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def avatar_url(options={})
|
|
245
|
+
get("/v2/me/avatar_url", options)[:body][:avatar_url]
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# Perform an HTTP GET request
|
|
249
|
+
def get(path, params={}, options={})
|
|
250
|
+
request(:get, path, params, options)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
# Perform an HTTP POST request
|
|
254
|
+
def post(path, params={}, options={})
|
|
255
|
+
request(:post, path, params, options)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
# Perform an HTTP UPDATE request
|
|
259
|
+
def put(path, params={}, options={})
|
|
260
|
+
request(:put, path, params, options)
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# Perform an HTTP DELETE request
|
|
264
|
+
def delete(path, params={}, options={})
|
|
265
|
+
request(:delete, path, params, options)
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# Returns a Faraday::Connection object
|
|
269
|
+
#
|
|
270
|
+
# @return [Faraday::Connection]
|
|
271
|
+
def connection
|
|
272
|
+
@connection ||= Faraday.new(@endpoint, @connection_options.merge(:builder => @middleware))
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# Perform an HTTP Request
|
|
276
|
+
def request(method, path, params, options)
|
|
277
|
+
uri = options[:endpoint] || @endpoint
|
|
278
|
+
uri = URI(uri) unless uri.respond_to?(:host)
|
|
279
|
+
uri += path
|
|
280
|
+
request_headers = {}
|
|
281
|
+
params[:api_key] = @api_key unless @api_key.nil?
|
|
282
|
+
|
|
283
|
+
if self.credentials?
|
|
284
|
+
# When posting a file, don't sign any params
|
|
285
|
+
signature_params = if [:post, :put].include?(method.to_sym) && params.values.any?{|value| value.is_a?(File) || (value.is_a?(Hash) && (value[:io].is_a?(IO) || value[:io].is_a?(StringIO)))}
|
|
286
|
+
{}
|
|
287
|
+
else
|
|
288
|
+
params
|
|
289
|
+
end
|
|
290
|
+
authorization = SimpleOAuth::Header.new(method, uri, signature_params, credentials)
|
|
291
|
+
request_headers[:authorization] = authorization.to_s.sub('OAuth', "Bearer")
|
|
292
|
+
end
|
|
293
|
+
connection.url_prefix = options[:endpoint] || @endpoint
|
|
294
|
+
connection.run_request(method.to_sym, path, nil, request_headers) do |request|
|
|
295
|
+
unless params.empty?
|
|
296
|
+
case request.method
|
|
297
|
+
when :post, :put
|
|
298
|
+
request.body = params
|
|
299
|
+
else
|
|
300
|
+
request.params.update(params)
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
yield request if block_given?
|
|
304
|
+
end.env
|
|
305
|
+
rescue Faraday::Error::ClientError
|
|
306
|
+
raise ACTV::Error::ClientError
|
|
307
|
+
end
|
|
308
|
+
# Check whether credentials are present
|
|
309
|
+
#
|
|
310
|
+
# @return [Boolean]
|
|
311
|
+
def credentials?
|
|
312
|
+
credentials.values.all?
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
private
|
|
316
|
+
|
|
317
|
+
# Credentials hash
|
|
318
|
+
#
|
|
319
|
+
# @return [Hash]
|
|
320
|
+
def credentials
|
|
321
|
+
{
|
|
322
|
+
# :consumer_key => @consumer_key,
|
|
323
|
+
# :consumer_secret => @consumer_secret,
|
|
324
|
+
:token => @oauth_token
|
|
325
|
+
# :token_secret => @oauth_token_secret,
|
|
326
|
+
}
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
end
|
|
330
|
+
end
|