playapi 0.0.3 → 0.1.5
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/lib/playapi.rb +14 -1
- data/lib/playapi/account.rb +34 -0
- data/lib/playapi/base.rb +124 -0
- data/lib/playapi/campaign.rb +7 -1
- data/lib/playapi/checkin.rb +6 -0
- data/lib/playapi/client.rb +31 -18
- data/lib/playapi/configurable.rb +6 -5
- data/lib/playapi/custom.rb +7 -0
- data/lib/playapi/entity.rb +2 -1
- data/lib/playapi/feature.rb +26 -4
- data/lib/playapi/foursquare.rb +10 -0
- data/lib/playapi/identity.rb +49 -0
- data/lib/playapi/instagrabber.rb +6 -0
- data/lib/playapi/instapic.rb +5 -0
- data/lib/playapi/interaction.rb +27 -3
- data/lib/playapi/picking.rb +17 -0
- data/lib/playapi/snap.rb +5 -0
- data/lib/playapi/snapchatter.rb +11 -0
- data/lib/playapi/tweet.rb +5 -0
- data/lib/playapi/twitter_scraper.rb +6 -0
- data/lib/playapi/utils.rb +27 -10
- data/lib/playapi/validation/instapic.rb +1 -1
- data/lib/playapi/validation/{twitterscraper.rb → twitter_scraper.rb} +1 -1
- data/lib/playapi/vine.rb +5 -0
- data/lib/playapi/vine_scraper.rb +6 -0
- data/lib/playapi/visual.rb +1 -0
- data/lib/playapi/voting.rb +6 -0
- metadata +19 -3
data/lib/playapi.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
require 'faraday'
|
|
2
2
|
require 'faraday_middleware'
|
|
3
|
-
require 'hashie'
|
|
4
3
|
require 'playapi/configurable'
|
|
5
4
|
require 'playapi/client'
|
|
6
5
|
require 'playapi/entity'
|
|
@@ -9,6 +8,20 @@ require 'playapi/feature'
|
|
|
9
8
|
require 'playapi/campaign'
|
|
10
9
|
require 'playapi/visual'
|
|
11
10
|
require 'playapi/utils'
|
|
11
|
+
require 'playapi/instapic'
|
|
12
|
+
require 'playapi/checkin'
|
|
13
|
+
require 'playapi/custom'
|
|
14
|
+
require 'playapi/tweet'
|
|
15
|
+
require 'playapi/twitter_scraper'
|
|
16
|
+
require 'playapi/instagrabber'
|
|
17
|
+
require 'playapi/foursquare'
|
|
18
|
+
require 'playapi/picking'
|
|
19
|
+
require 'playapi/voting'
|
|
20
|
+
require 'playapi/snapchatter'
|
|
21
|
+
require 'playapi/snap'
|
|
22
|
+
require 'playapi/account'
|
|
23
|
+
require 'playapi/vine'
|
|
24
|
+
require 'playapi/vine_scraper'
|
|
12
25
|
|
|
13
26
|
|
|
14
27
|
module Playapi
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'playapi/utils'
|
|
2
|
+
require 'playapi/identity'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
module Playapi
|
|
6
|
+
class Account < Playapi::Identity
|
|
7
|
+
extend Playapi::Utils
|
|
8
|
+
attr_reader :service_name, :service_id
|
|
9
|
+
|
|
10
|
+
def push
|
|
11
|
+
self.attrs = Playapi::Account.update(id, @attrs).attrs
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class << self
|
|
15
|
+
|
|
16
|
+
def list
|
|
17
|
+
url = "api/v2/accounts"
|
|
18
|
+
get_objects(:get, "accounts", url)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def get(id)
|
|
22
|
+
url = "api/v2/accounts/#{id}"
|
|
23
|
+
get_object(:get, "account", url)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def update(id, opts)
|
|
27
|
+
url = "api/v2/accounts/#{id}"
|
|
28
|
+
get_object(:put, "account", url, {:account => opts})
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/playapi/base.rb
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
module Playapi
|
|
2
|
+
class Base
|
|
3
|
+
# Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
|
|
4
|
+
#
|
|
5
|
+
# @param attrs [Array, Set, Symbol]
|
|
6
|
+
def self.attr_reader(*attrs)
|
|
7
|
+
mod = Module.new do
|
|
8
|
+
attrs.each do |attribute|
|
|
9
|
+
define_method attribute do
|
|
10
|
+
@attrs[attribute.to_sym]
|
|
11
|
+
end
|
|
12
|
+
define_method "#{attribute}?" do
|
|
13
|
+
!!@attrs[attribute.to_sym]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
const_set(:Attributes, mod)
|
|
18
|
+
include mod
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# return [Playapi::IdentityMap]
|
|
22
|
+
def self.identity_map
|
|
23
|
+
return unless Playapi.identity_map
|
|
24
|
+
@identity_map = Playapi.identity_map.new unless defined?(@identity_map) && @identity_map.class == Playapi.identity_map
|
|
25
|
+
@identity_map
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Retrieves an object from the identity map.
|
|
29
|
+
#
|
|
30
|
+
# @param attrs [Hash]
|
|
31
|
+
# @return [Playapi::Base]
|
|
32
|
+
# THIS NEEDS TO BE REIMPLEMENTED
|
|
33
|
+
def self.fetch(attrs)
|
|
34
|
+
return unless identity_map
|
|
35
|
+
if object = identity_map.fetch("#{self.class.to_s.downcase}:#{attrs[:id]}")
|
|
36
|
+
return object
|
|
37
|
+
end
|
|
38
|
+
return yield if block_given?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Stores an object in the identity map.
|
|
42
|
+
#
|
|
43
|
+
# @param object [Object]
|
|
44
|
+
# @return [Playapi::Base]
|
|
45
|
+
def self.store(object)
|
|
46
|
+
return object unless identity_map
|
|
47
|
+
# should this operate on type even though not ever response returns type? (campaign/entities)
|
|
48
|
+
identity_map.store("#{self.class.to_s.downcase}:#{object.id}", object)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Returns a new object based on the response hash
|
|
52
|
+
#
|
|
53
|
+
# @param response [Hash]
|
|
54
|
+
# @return [Playapi::Base]
|
|
55
|
+
def self.from_response(response={})
|
|
56
|
+
fetch_or_new(response[:body])
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Retrieves an object from the identity map, or stores it in the
|
|
60
|
+
# identity map if it doesn't already exist.
|
|
61
|
+
#
|
|
62
|
+
# @param attrs [Hash]
|
|
63
|
+
# @return [Playapi::Base]
|
|
64
|
+
def self.fetch_or_new(attrs={})
|
|
65
|
+
return unless attrs
|
|
66
|
+
return new(attrs) unless identity_map
|
|
67
|
+
|
|
68
|
+
fetch(attrs) do
|
|
69
|
+
object = new(attrs)
|
|
70
|
+
store(object)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Initializes a new object
|
|
75
|
+
#
|
|
76
|
+
# @param attrs [Hash]
|
|
77
|
+
# @return [Playapi::Base]
|
|
78
|
+
def initialize(attrs={})
|
|
79
|
+
@attrs = attrs
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Fetches an attribute of an object using hash notation
|
|
83
|
+
#
|
|
84
|
+
# @param method [String, Symbol] Message to send to the object
|
|
85
|
+
def [](method)
|
|
86
|
+
send(method.to_sym)
|
|
87
|
+
rescue NoMethodError
|
|
88
|
+
nil
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Retrieve the attributes of an object
|
|
92
|
+
#
|
|
93
|
+
# @return [Hash]
|
|
94
|
+
def attrs
|
|
95
|
+
@attrs
|
|
96
|
+
end
|
|
97
|
+
alias to_hash attrs
|
|
98
|
+
|
|
99
|
+
# Update the attributes of an object
|
|
100
|
+
#
|
|
101
|
+
# @param attrs [Hash]
|
|
102
|
+
# @return [Playapi::Base]
|
|
103
|
+
def update(attrs)
|
|
104
|
+
@attrs.update(attrs)
|
|
105
|
+
self
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
protected
|
|
109
|
+
|
|
110
|
+
# @param attr [Symbol]
|
|
111
|
+
# @param other [Playapi::Base]
|
|
112
|
+
# @return [Boolean]
|
|
113
|
+
def attr_equal(attr, other)
|
|
114
|
+
self.class == other.class && !other.send(attr).nil? && send(attr) == other.send(attr)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# @param other [Playapi::Base]
|
|
118
|
+
# @return [Boolean]
|
|
119
|
+
def attrs_equal(other)
|
|
120
|
+
self.class == other.class && !other.attrs.empty? && attrs == other.attrs
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
end
|
data/lib/playapi/campaign.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
require 'playapi/utils'
|
|
2
|
+
require 'playapi/identity'
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
module Playapi
|
|
4
|
-
class Campaign
|
|
6
|
+
class Campaign < Playapi::Identity
|
|
5
7
|
extend Playapi::Utils
|
|
6
8
|
|
|
7
9
|
# stub this out for now, it will probably do crazy stuff when we integrate campaign controls.
|
|
@@ -42,6 +44,10 @@ module Playapi
|
|
|
42
44
|
get_object(:get, "results", url, opts)
|
|
43
45
|
end
|
|
44
46
|
|
|
47
|
+
def features
|
|
48
|
+
Playapi::Feature.list
|
|
49
|
+
end
|
|
50
|
+
|
|
45
51
|
def create(opts)
|
|
46
52
|
#raise "WE DON'T MAKE CAMPAIGNS YET"
|
|
47
53
|
#url = "api/v2/campaigns"
|
data/lib/playapi/client.rb
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
require 'playapi/configurable'
|
|
2
|
+
require 'simple_oauth'
|
|
1
3
|
require 'faraday'
|
|
2
4
|
|
|
3
5
|
module Playapi
|
|
4
6
|
class Client
|
|
5
|
-
include Playapi::Configurable
|
|
7
|
+
include Playapi::Configurable
|
|
6
8
|
|
|
7
9
|
def initialize(options={})
|
|
8
10
|
Playapi::Configurable.keys.each do |key|
|
|
@@ -10,33 +12,44 @@ module Playapi
|
|
|
10
12
|
end
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
params = {}
|
|
15
|
-
params[:client_id] = @client_id
|
|
16
|
-
params[:client_secret] = @client_secret
|
|
17
|
-
params[:token] = @oauth_token
|
|
18
|
-
|
|
15
|
+
private
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
def connection
|
|
18
|
+
params = {}
|
|
19
|
+
#params[:client_id] = @client_id
|
|
20
|
+
#params[:client_secret] = @client_secret
|
|
21
|
+
#params[:token] = @oauth_token
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@connection ||= Faraday::Connection.new(:url => @endpoint,
|
|
25
|
+
:ssl => @ssl,
|
|
26
|
+
:params => params
|
|
27
|
+
) do |builder|
|
|
28
|
+
@connection_middleware.each do |mw|
|
|
29
|
+
builder.use *mw
|
|
30
|
+
end
|
|
31
|
+
builder.adapter Faraday.default_adapter
|
|
27
32
|
end
|
|
28
|
-
builder.adapter Faraday.default_adapter
|
|
29
33
|
end
|
|
30
|
-
end
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
def request(method, path, params={}, signature_params=params)
|
|
36
|
+
connection.send(method.to_sym, path, params) do |request|
|
|
37
|
+
request.headers["x-authorization"] = auth_header(method.to_sym, path, signature_params).to_s
|
|
38
|
+
request.headers.merge!(default_headers)
|
|
39
|
+
end.env
|
|
40
|
+
end
|
|
33
41
|
|
|
34
42
|
def default_headers
|
|
35
43
|
headers = {
|
|
36
44
|
:accept => "application/json",
|
|
37
|
-
:user_agent => "PlayAPI Gem 0.
|
|
45
|
+
:user_agent => "PlayAPI Gem 0.1.5"
|
|
38
46
|
}
|
|
39
47
|
end
|
|
40
48
|
|
|
49
|
+
def auth_header(method, path, params)
|
|
50
|
+
uri = URI(@endpoint + path)
|
|
51
|
+
SimpleOAuth::Header.new(method, uri, params, credentials)
|
|
52
|
+
end
|
|
53
|
+
|
|
41
54
|
end
|
|
42
55
|
end
|
data/lib/playapi/configurable.rb
CHANGED
|
@@ -9,7 +9,6 @@ module Playapi
|
|
|
9
9
|
DEFAULT_CONNECTION_MIDDLEWARE = [
|
|
10
10
|
Faraday::Request::Multipart,
|
|
11
11
|
Faraday::Request::UrlEncoded,
|
|
12
|
-
FaradayMiddleware::Mashify,
|
|
13
12
|
FaradayMiddleware::ParseJson
|
|
14
13
|
]
|
|
15
14
|
|
|
@@ -21,6 +20,7 @@ module Playapi
|
|
|
21
20
|
:client_secret,
|
|
22
21
|
:oauth_token,
|
|
23
22
|
:endpoint,
|
|
23
|
+
:token_secret,
|
|
24
24
|
:connection_options,
|
|
25
25
|
:identity_map,
|
|
26
26
|
:connection_middleware,
|
|
@@ -45,10 +45,10 @@ module Playapi
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def reset!
|
|
48
|
-
defaultz = {client_id: "
|
|
48
|
+
defaultz = {client_id: "F1Ox4PEhf1eiNGRge7kscIRgay1mh8cbi2zruIC1OI", client_secret: "xLeR0lXVdEtfjwP04w4FJKZm8KxS97Qg5o8Xbyw3JeE", oauth_token: "KqoCXCoyhrJTyGFtCYmiUcWModkTYBILiMHyKGQCBYg", token_secret: "b63V8SyY9ip8yigE5o6bsf3HFyza1wRfLnl3HyhhPz4", endpoint: "http://api.papi.io/"}
|
|
49
49
|
# we can probably chuck conn_ops
|
|
50
50
|
conn_ops = {
|
|
51
|
-
:connection_options => {:headers => {:accept => "application/json", :user_agent => "PlayAPI Gem 0.
|
|
51
|
+
:connection_options => {:headers => {:accept => "application/json", :user_agent => "PlayAPI Gem 0.1.1"},
|
|
52
52
|
:ssl => {:verify => false}}
|
|
53
53
|
}
|
|
54
54
|
#defaultz.merge!(conn_ops)
|
|
@@ -67,9 +67,10 @@ module Playapi
|
|
|
67
67
|
# @return [Hash]
|
|
68
68
|
def credentials
|
|
69
69
|
{
|
|
70
|
-
:
|
|
71
|
-
:
|
|
70
|
+
:consumer_key => @client_id,
|
|
71
|
+
:consumer_secret => @client_secret,
|
|
72
72
|
:token => @oauth_token,
|
|
73
|
+
:token_secret => @token_secret
|
|
73
74
|
}
|
|
74
75
|
end
|
|
75
76
|
|
data/lib/playapi/entity.rb
CHANGED
data/lib/playapi/feature.rb
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
require 'playapi/utils'
|
|
2
2
|
require 'playapi/validation/feature'
|
|
3
3
|
require 'playapi/validation/instagrabber'
|
|
4
|
-
require 'playapi/validation/
|
|
4
|
+
require 'playapi/validation/twitter_scraper'
|
|
5
5
|
require 'playapi/validation/picking'
|
|
6
|
+
require 'playapi/identity'
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
module Playapi
|
|
9
|
-
class Feature
|
|
10
|
+
class Feature < Playapi::Identity
|
|
10
11
|
extend Playapi::Utils
|
|
12
|
+
attr_reader :id, :campaign_id, :name, :live, :default_points, :attrs
|
|
11
13
|
|
|
12
|
-
def
|
|
14
|
+
def interactions
|
|
15
|
+
Playapi::Interaction.by_feature(id)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def push
|
|
19
|
+
Playapi::Feature.update(id, @attrs)
|
|
20
|
+
end
|
|
13
21
|
|
|
22
|
+
def destroy
|
|
23
|
+
Playapi::Feature.destroy(id)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def campaign
|
|
27
|
+
Playapi::Campaign.get(@attrs["campaign_id"])
|
|
14
28
|
end
|
|
15
29
|
|
|
16
30
|
class << self
|
|
@@ -18,7 +32,7 @@ module Playapi
|
|
|
18
32
|
# TODO: add filters and options
|
|
19
33
|
def list
|
|
20
34
|
url = "api/v2/features"
|
|
21
|
-
|
|
35
|
+
get_objects(:get, "features", url)
|
|
22
36
|
end
|
|
23
37
|
|
|
24
38
|
# Fetch a feature by id
|
|
@@ -64,6 +78,14 @@ module Playapi
|
|
|
64
78
|
url = "api/v2/features/#{id}"
|
|
65
79
|
get_object(:delete, "feature", url)
|
|
66
80
|
end
|
|
81
|
+
# pass in a hash of options to find things, options include: type and name
|
|
82
|
+
# returns an array
|
|
83
|
+
# name=String
|
|
84
|
+
# type=String
|
|
85
|
+
def find_by_facet(opts)
|
|
86
|
+
url = "api/v2/features/facet"
|
|
87
|
+
get_objects(:get, :features, url, opts)
|
|
88
|
+
end
|
|
67
89
|
|
|
68
90
|
end
|
|
69
91
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module Playapi
|
|
2
|
+
class Foursquare < Playapi::Feature
|
|
3
|
+
attr_accessor :authenticated_venues, :client_id, :client_secret, :oauth_token, :push_secret
|
|
4
|
+
|
|
5
|
+
def near(coords)
|
|
6
|
+
#This would be a nice function, no? Shall I add an endpoint just for location items?
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'playapi/base'
|
|
2
|
+
|
|
3
|
+
module Playapi
|
|
4
|
+
class Identity < Playapi::Base
|
|
5
|
+
|
|
6
|
+
def self.fetch(attrs)
|
|
7
|
+
return unless identity_map
|
|
8
|
+
|
|
9
|
+
id = attrs[:id]
|
|
10
|
+
if id && object = identity_map.fetch(id)
|
|
11
|
+
return object.update(attrs)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
return yield if block_given?
|
|
15
|
+
raise "Not Found!"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Stores an object in the identity map.
|
|
19
|
+
#
|
|
20
|
+
# @param object [Object]
|
|
21
|
+
# @return [Twitter::Identity]
|
|
22
|
+
def self.store(object)
|
|
23
|
+
return object unless identity_map
|
|
24
|
+
identity_map.store(object.id, object)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Initializes a new object
|
|
28
|
+
#
|
|
29
|
+
# @param attrs [Hash]
|
|
30
|
+
# @raise [ArgumentError] Error raised when supplied argument is missing an :id key.
|
|
31
|
+
# @return [Twitter::Identity]
|
|
32
|
+
def initialize(attrs={})
|
|
33
|
+
super
|
|
34
|
+
raise ArgumentError, "argument must have an :id key" unless id
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# @param other [Twitter::Identity]
|
|
38
|
+
# @return [Boolean]
|
|
39
|
+
def ==(other)
|
|
40
|
+
super || attr_equal(:id, other) || attrs_equal(other)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @return [Integer]
|
|
44
|
+
def id
|
|
45
|
+
@attrs[:id]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
data/lib/playapi/interaction.rb
CHANGED
|
@@ -2,13 +2,36 @@ require 'playapi/utils'
|
|
|
2
2
|
require 'playapi/validation/instapic'
|
|
3
3
|
require 'playapi/validation/tweet'
|
|
4
4
|
require 'playapi/validation/custom'
|
|
5
|
+
require 'playapi/identity'
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
module Playapi
|
|
9
|
-
class Interaction
|
|
10
|
+
class Interaction < Playapi::Identity
|
|
10
11
|
extend Playapi::Utils
|
|
11
12
|
|
|
13
|
+
attr_reader :id, :text, :campaign_id, :entity_id, :feature_id
|
|
14
|
+
|
|
15
|
+
def feature
|
|
16
|
+
Playapi::Feature.get(@attrs["feature_id"])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def entity
|
|
20
|
+
Playapi::Entity.get(@attrs["entity_id"])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def push
|
|
24
|
+
self.attrs = Playapi::Interaction.update(id, @attrs).attrs
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def destroy
|
|
28
|
+
Playapi::Interaction.destroy(id)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def campaign
|
|
32
|
+
Playapi::Campaign.get(@attrs["campaign_id"])
|
|
33
|
+
end
|
|
34
|
+
|
|
12
35
|
class << self
|
|
13
36
|
|
|
14
37
|
# Get interactions for a campaign, optional paramaters include
|
|
@@ -21,7 +44,7 @@ module Playapi
|
|
|
21
44
|
# :type=STRING (Valid options are Instapic, Tweet, Checkin)
|
|
22
45
|
def list
|
|
23
46
|
url = "api/v2/interactions"
|
|
24
|
-
|
|
47
|
+
get_objects(:get, "interactions", url)
|
|
25
48
|
end
|
|
26
49
|
|
|
27
50
|
# Get an interaction with the given id
|
|
@@ -52,10 +75,11 @@ module Playapi
|
|
|
52
75
|
end
|
|
53
76
|
|
|
54
77
|
# pass in a hash of options to find things, currently the only one that is applicable is content_id
|
|
78
|
+
# returns an array
|
|
55
79
|
# content_id=String
|
|
56
80
|
def find_by_facet(opts)
|
|
57
81
|
url = "api/v2/interactions/facet"
|
|
58
|
-
|
|
82
|
+
get_objects(:get, :interactions, url, opts)
|
|
59
83
|
end
|
|
60
84
|
|
|
61
85
|
# Create a classed interaction for authed campaign
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'playapi/utils'
|
|
2
|
+
require 'playapi/feature'
|
|
3
|
+
|
|
4
|
+
module Playapi
|
|
5
|
+
class Picking < Playapi::Feature
|
|
6
|
+
extend Playapi::Utils
|
|
7
|
+
attr_reader :target_features, :target_class
|
|
8
|
+
|
|
9
|
+
# gets a set of interactions from a picking feature on playapi
|
|
10
|
+
def get_set(set_size=2, opts={})
|
|
11
|
+
url = "api/v2/picks/#{id}"
|
|
12
|
+
# public and private don't matter since you can use send... :/
|
|
13
|
+
self.class.send(:get_objects, :get, "results", url, opts.merge!(set_size: set_size))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/playapi/snap.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Playapi
|
|
2
|
+
class Snapchatter < Playapi::Feature
|
|
3
|
+
attr_reader :username, :password
|
|
4
|
+
|
|
5
|
+
def send_snapchat(names=[], url='', opts={})
|
|
6
|
+
# awaiting finalization of end point
|
|
7
|
+
url = "/api/v2/snapchatter/#{id}/send_snapchat"
|
|
8
|
+
self.class.send(:get_objects, :post, "results", opts.merge!(usernames: names, source: url))
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
data/lib/playapi/utils.rb
CHANGED
|
@@ -8,24 +8,41 @@ module Playapi
|
|
|
8
8
|
|
|
9
9
|
private
|
|
10
10
|
|
|
11
|
-
def
|
|
12
|
-
res = Playapi.client.
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
def get_objects(method, key, path, options={})
|
|
12
|
+
res = Playapi.client.send(:request, method.to_sym, path, options)
|
|
13
|
+
puts "\n\n#{res.inspect}\n\n"
|
|
14
|
+
if res[:status] == 200
|
|
15
|
+
res[:body][key].collect{|y| sym_hash = convert_string_hash_to_sym(y); eval "#{sym_hash[:type]}.new(#{sym_hash})"}
|
|
15
16
|
else
|
|
16
|
-
errors = res
|
|
17
|
-
raise "Error returned: #{res
|
|
17
|
+
#errors = res[:body][:errors]
|
|
18
|
+
raise "Error returned: #{res[:status]} #{res[:body][:errors]}"
|
|
18
19
|
end
|
|
19
20
|
end
|
|
20
21
|
|
|
21
|
-
def
|
|
22
|
-
res = Playapi.client.
|
|
22
|
+
def get_object(method, key, path, options={})
|
|
23
|
+
res = Playapi.client.send(:request, method.to_sym, path, options)
|
|
23
24
|
if res.status == 200
|
|
24
|
-
res.body
|
|
25
|
+
sym_hash = convert_string_hash_to_sym(res.body[key])
|
|
26
|
+
eval "#{sym_hash[:type]}.new(#{sym_hash})"
|
|
25
27
|
else
|
|
26
|
-
|
|
28
|
+
errors = res.body["errors"]
|
|
29
|
+
raise "Error returned: #{res.status} #{errors}"
|
|
27
30
|
end
|
|
28
31
|
end
|
|
29
32
|
|
|
33
|
+
def get_raw
|
|
34
|
+
res = Playapi.client.send(:request, method.to_sym, path, options)
|
|
35
|
+
if res.status == 200
|
|
36
|
+
res.body[key]
|
|
37
|
+
else
|
|
38
|
+
errors = res.body["errors"]
|
|
39
|
+
raise "Error returned: #{res.status} #{errors}"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def convert_string_hash_to_sym(string_hash)
|
|
44
|
+
q = string_hash.inject({}){|q,(k,v)| q[k.to_sym] = v; q}
|
|
45
|
+
end
|
|
46
|
+
|
|
30
47
|
end
|
|
31
48
|
end
|
data/lib/playapi/vine.rb
ADDED
data/lib/playapi/visual.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: playapi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
12
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: Interact with PlayAPI
|
|
15
15
|
email: france@playapi.com
|
|
@@ -29,10 +29,26 @@ files:
|
|
|
29
29
|
- lib/playapi/validation/instapic.rb
|
|
30
30
|
- lib/playapi/validation/tweet.rb
|
|
31
31
|
- lib/playapi/validation/instagrabber.rb
|
|
32
|
-
- lib/playapi/validation/
|
|
32
|
+
- lib/playapi/validation/twitter_scraper.rb
|
|
33
33
|
- lib/playapi/validation/picking.rb
|
|
34
34
|
- lib/playapi/validation/feature.rb
|
|
35
35
|
- lib/playapi/validation/custom.rb
|
|
36
|
+
- lib/playapi/base.rb
|
|
37
|
+
- lib/playapi/identity.rb
|
|
38
|
+
- lib/playapi/instapic.rb
|
|
39
|
+
- lib/playapi/checkin.rb
|
|
40
|
+
- lib/playapi/custom.rb
|
|
41
|
+
- lib/playapi/tweet.rb
|
|
42
|
+
- lib/playapi/twitter_scraper.rb
|
|
43
|
+
- lib/playapi/picking.rb
|
|
44
|
+
- lib/playapi/instagrabber.rb
|
|
45
|
+
- lib/playapi/foursquare.rb
|
|
46
|
+
- lib/playapi/voting.rb
|
|
47
|
+
- lib/playapi/snapchatter.rb
|
|
48
|
+
- lib/playapi/snap.rb
|
|
49
|
+
- lib/playapi/account.rb
|
|
50
|
+
- lib/playapi/vine.rb
|
|
51
|
+
- lib/playapi/vine_scraper.rb
|
|
36
52
|
homepage: http://rubygems.org/gems/playapi
|
|
37
53
|
licenses: []
|
|
38
54
|
post_install_message:
|