stream-ruby 2.2.3 → 2.2.4
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.
- checksums.yaml +4 -4
- data/README.md +9 -10
- data/lib/stream.rb +1 -1
- data/lib/stream/base.rb +13 -13
- data/lib/stream/batch.rb +34 -36
- data/lib/stream/client.rb +105 -111
- data/lib/stream/errors.rb +5 -0
- data/lib/stream/exceptions.rb +2 -8
- data/lib/stream/feed.rb +114 -121
- data/lib/stream/signedrequest.rb +28 -31
- data/lib/stream/signer.rb +20 -21
- data/lib/stream/version.rb +1 -1
- metadata +4 -28
- data/lib/coverage/assets/0.8.0/application.css +0 -799
- data/lib/coverage/assets/0.8.0/application.js +0 -1559
- data/lib/coverage/assets/0.8.0/colorbox/border.png +0 -0
- data/lib/coverage/assets/0.8.0/colorbox/controls.png +0 -0
- data/lib/coverage/assets/0.8.0/colorbox/loading.gif +0 -0
- data/lib/coverage/assets/0.8.0/colorbox/loading_background.png +0 -0
- data/lib/coverage/assets/0.8.0/favicon_green.png +0 -0
- data/lib/coverage/assets/0.8.0/favicon_red.png +0 -0
- data/lib/coverage/assets/0.8.0/favicon_yellow.png +0 -0
- data/lib/coverage/assets/0.8.0/loading.gif +0 -0
- data/lib/coverage/assets/0.8.0/magnify.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/lib/coverage/assets/0.8.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/lib/coverage/index.html +0 -1162
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 359b8889235fc2df03b84b7330e7ce994dcd1618
|
4
|
+
data.tar.gz: 709c31cfb3240ef88e63e2c0171a2f75b2b369e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bff2687b955dfae9cb454ca4affa5d241cc12ae3ad6e823fdab5edeec641c3b990c01110fbdfe813c336e449a0d9504e2ac94fb68034275d2a54a289c3421e4
|
7
|
+
data.tar.gz: d4e5dd145db0481d83ca6fc4838c86687a1f34ab3983d7821fa69227d483c92c43086eef4ed23e222975a38dfe82dbc930ffbb799a274eb52f224eef84babeed
|
data/README.md
CHANGED
@@ -3,13 +3,8 @@ stream-ruby
|
|
3
3
|
|
4
4
|
[](https://travis-ci.org/GetStream/stream-ruby) [](http://badge.fury.io/rb/stream-ruby)
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
stream-ruby is a Ruby client for [Stream](https://getstream.io/).
|
10
|
-
|
11
|
-
**Users of versions < 2.0.0, Stream::Feed constructor signature and other methods has changed. Please read this before upgrading:** [Breaking Changes](http://github.com/GetStream/stream-ruby/blob/master/upgrading.txt)
|
12
|
-
|
6
|
+
stream-ruby is the official Ruby client for [Stream](https://getstream.io/), a web service for building scalable newsfeeds and activity streams.
|
7
|
+
The full documentation is available on [GetStream.io/docs](http://getstream.io/docs/). Note that there is also a [higher level Rails integration](https://github.com/getstream/stream-rails) which hooks into your ORM.
|
13
8
|
|
14
9
|
### Installation
|
15
10
|
|
@@ -61,14 +56,14 @@ activities = [
|
|
61
56
|
[:actor => '1', :verb => 'tweet', :object => '1'],
|
62
57
|
[:actor => '2', :verb => 'like', :object => '3']
|
63
58
|
]
|
64
|
-
user_feed_1.
|
59
|
+
user_feed_1.add_activities(activities)
|
65
60
|
|
66
61
|
# Batch following many feeds (requires ruby 2.1 or later)
|
67
|
-
follows = {
|
62
|
+
follows = [{
|
68
63
|
:source => 'flat:1', :target => 'user:1',
|
69
64
|
:source => 'flat:1', :target => 'user:2',
|
70
65
|
:source => 'flat:1', :target => 'user:3'
|
71
|
-
]
|
66
|
+
}]
|
72
67
|
client.follow_many(follows)
|
73
68
|
|
74
69
|
# Add an activity and push it to other feeds too using the `to` field
|
@@ -104,6 +99,10 @@ user_feed_1.following(10, 10)
|
|
104
99
|
# Check if user_feed_1 follows specific feeds
|
105
100
|
user_feed_1.following(0, 2, filter=['user:42', 'user:43'])
|
106
101
|
|
102
|
+
# Add one activity to many feeds in one request
|
103
|
+
feeds = ['flat:1', 'flat:2', 'flat:3', 'flat:4']
|
104
|
+
activity = {:actor => "User:2", :verb => "pin", :object => "Place:42", :target => "Board:1"}
|
105
|
+
client.add_to_many(activity, feeds)
|
107
106
|
```
|
108
107
|
|
109
108
|
Docs are available on [GetStream.io](http://getstream.io/docs/).
|
data/lib/stream.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require "stream/base"
|
data/lib/stream/base.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "json"
|
2
|
+
require "stream/client"
|
3
|
+
require "stream/errors"
|
4
|
+
require "stream/version"
|
5
|
+
require "stream/signer"
|
6
6
|
|
7
7
|
module Stream
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
class << self
|
9
|
+
def connect(api_key, api_secret)
|
10
|
+
Stream::Client.new(api_key, api_secret)
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
end
|
13
|
+
def get_feed_slug_and_id(feed_id)
|
14
|
+
feed_id.sub(":", "")
|
16
15
|
end
|
17
|
-
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/stream/batch.rb
CHANGED
@@ -1,41 +1,39 @@
|
|
1
1
|
module Stream
|
2
|
-
|
3
2
|
module Batch
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# Adds an activity to many feeds in one single request
|
26
|
-
#
|
27
|
-
# @param [Hash] activity_data the activity do add
|
28
|
-
# @param [Array<string>] feeds list of feeds (eg. 'user:1', 'flat:2')
|
29
|
-
#
|
30
|
-
# @return [nil]
|
31
|
-
#
|
32
|
-
def add_to_many(activity_data, feeds)
|
33
|
-
data = {
|
34
|
-
:feeds => feeds,
|
35
|
-
:activity => activity_data
|
36
|
-
}
|
37
|
-
self.make_signed_request(:post, '/feed/add_to_many/', {}, data)
|
38
|
-
end
|
3
|
+
#
|
4
|
+
# Follows many feeds in one single request
|
5
|
+
#
|
6
|
+
# @param [Array<Hash<:source, :target>>] follows the list of follows
|
7
|
+
#
|
8
|
+
# @return [nil]
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
#
|
13
|
+
# follows = [
|
14
|
+
# {:source => 'flat:1', :target => 'user:1'},
|
15
|
+
# {:source => 'flat:1', :target => 'user:3'}
|
16
|
+
# ]
|
17
|
+
# @client.follow_many(follows)
|
18
|
+
#
|
19
|
+
def follow_many(follows)
|
20
|
+
make_signed_request(:post, "/follow_many/", {}, follows)
|
39
21
|
end
|
40
22
|
|
23
|
+
#
|
24
|
+
# Adds an activity to many feeds in one single request
|
25
|
+
#
|
26
|
+
# @param [Hash] activity_data the activity do add
|
27
|
+
# @param [Array<string>] feeds list of feeds (eg. 'user:1', 'flat:2')
|
28
|
+
#
|
29
|
+
# @return [nil]
|
30
|
+
#
|
31
|
+
def add_to_many(activity_data, feeds)
|
32
|
+
data = {
|
33
|
+
:feeds => feeds,
|
34
|
+
:activity => activity_data
|
35
|
+
}
|
36
|
+
make_signed_request(:post, "/feed/add_to_many/", {}, data)
|
37
|
+
end
|
38
|
+
end
|
41
39
|
end
|
data/lib/stream/client.rb
CHANGED
@@ -1,123 +1,117 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
1
|
+
require "httparty"
|
2
|
+
require "stream/errors"
|
3
|
+
require "stream/feed"
|
4
|
+
require "stream/signer"
|
6
5
|
|
7
6
|
module Stream
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
#
|
27
|
-
# initializes a Stream API Client
|
28
|
-
#
|
29
|
-
# @param [string] api_key your application api_key
|
30
|
-
# @param [string] api_secret your application secret
|
31
|
-
# @param [string] app_id the id of your application (optional)
|
32
|
-
# @param [hash] opts extra options
|
33
|
-
#
|
34
|
-
# @example initialise the client to connect to EU-West location
|
35
|
-
# Stream::Client.new('my_key', 'my_secret', 'my_app_id', :location => 'us-east')
|
36
|
-
#
|
37
|
-
def initialize(api_key='', api_secret='', app_id=nil, opts={})
|
38
|
-
if ENV['STREAM_URL'] =~ Stream::STREAM_URL_RE and (api_key.nil? || api_key.empty?)
|
39
|
-
matches = Stream::STREAM_URL_RE.match(ENV['STREAM_URL'])
|
40
|
-
api_key = matches['key']
|
41
|
-
api_secret = matches['secret']
|
42
|
-
app_id = matches['app_id']
|
43
|
-
opts[:location] = matches['location']
|
44
|
-
end
|
45
|
-
|
46
|
-
if api_key.nil? || api_key.empty?
|
47
|
-
raise ArgumentError, 'empty api_key parameter and missing or invalid STREAM_URL env variable'
|
48
|
-
end
|
49
|
-
|
50
|
-
@api_key = api_key
|
51
|
-
@api_secret = api_secret
|
52
|
-
@app_id = app_id
|
53
|
-
@location = opts[:location]
|
54
|
-
@api_version = opts.fetch(:api_version, 'v1.0')
|
55
|
-
@default_timeout = opts.fetch(:default_timeout, 3)
|
56
|
-
@signer = Stream::Signer.new(api_secret)
|
57
|
-
end
|
58
|
-
|
59
|
-
#
|
60
|
-
# Creates a feed instance
|
61
|
-
#
|
62
|
-
# @param [string] feed_slug the feed slug (eg. flat, aggregated...)
|
63
|
-
# @param [user_id] user_id the user_id of this feed (eg. User42)
|
64
|
-
#
|
65
|
-
# @return [Stream::Feed]
|
66
|
-
#
|
67
|
-
def feed(feed_slug, user_id)
|
68
|
-
token = @signer.sign(feed_slug, user_id)
|
69
|
-
Stream::Feed.new(self, feed_slug, user_id, token)
|
70
|
-
end
|
71
|
-
|
72
|
-
def get_default_params
|
73
|
-
{:api_key => @api_key}
|
74
|
-
end
|
75
|
-
|
76
|
-
def get_http_client
|
77
|
-
StreamHTTPClient.new(@api_version, @location, @default_timeout)
|
78
|
-
end
|
79
|
-
|
80
|
-
def make_query_params(params)
|
81
|
-
self.get_default_params.merge(params)
|
82
|
-
end
|
7
|
+
STREAM_URL_RE = %r{https\:\/\/(?<key>\w+)\:(?<secret>\w+)@((api\.)|((?<location>[-\w]+)\.))?getstream\.io\/[\w=-\?%&]+app_id=(?<app_id>\d+)}i
|
8
|
+
|
9
|
+
class Client
|
10
|
+
attr_reader :api_key
|
11
|
+
attr_reader :api_secret
|
12
|
+
attr_reader :app_id
|
13
|
+
attr_reader :api_version
|
14
|
+
attr_reader :location
|
15
|
+
attr_reader :default_timeout
|
16
|
+
|
17
|
+
if RUBY_VERSION.to_f >= 2.1
|
18
|
+
require "stream/batch"
|
19
|
+
require "stream/signedrequest"
|
20
|
+
|
21
|
+
include Stream::SignedRequest
|
22
|
+
include Stream::Batch
|
23
|
+
end
|
83
24
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
25
|
+
#
|
26
|
+
# initializes a Stream API Client
|
27
|
+
#
|
28
|
+
# @param [string] api_key your application api_key
|
29
|
+
# @param [string] api_secret your application secret
|
30
|
+
# @param [string] app_id the id of your application (optional)
|
31
|
+
# @param [hash] opts extra options
|
32
|
+
#
|
33
|
+
# @example initialise the client to connect to EU-West location
|
34
|
+
# Stream::Client.new('my_key', 'my_secret', 'my_app_id', :location => 'us-east')
|
35
|
+
#
|
36
|
+
def initialize(api_key = "", api_secret = "", app_id = nil, opts = {})
|
37
|
+
if ENV["STREAM_URL"] =~ Stream::STREAM_URL_RE && (api_key.nil? || api_key.empty?)
|
38
|
+
matches = Stream::STREAM_URL_RE.match(ENV["STREAM_URL"])
|
39
|
+
api_key = matches["key"]
|
40
|
+
api_secret = matches["secret"]
|
41
|
+
app_id = matches["app_id"]
|
42
|
+
opts[:location] = matches["location"]
|
43
|
+
end
|
44
|
+
|
45
|
+
if api_key.nil? || api_key.empty?
|
46
|
+
raise ArgumentError, "empty api_key parameter and missing or invalid STREAM_URL env variable"
|
47
|
+
end
|
48
|
+
|
49
|
+
@api_key = api_key
|
50
|
+
@api_secret = api_secret
|
51
|
+
@app_id = app_id
|
52
|
+
@location = opts[:location]
|
53
|
+
@api_version = opts.fetch(:api_version, "v1.0")
|
54
|
+
@default_timeout = opts.fetch(:default_timeout, 3)
|
55
|
+
@signer = Stream::Signer.new(api_secret)
|
56
|
+
end
|
88
57
|
|
58
|
+
#
|
59
|
+
# Creates a feed instance
|
60
|
+
#
|
61
|
+
# @param [string] feed_slug the feed slug (eg. flat, aggregated...)
|
62
|
+
# @param [user_id] user_id the user_id of this feed (eg. User42)
|
63
|
+
#
|
64
|
+
# @return [Stream::Feed]
|
65
|
+
#
|
66
|
+
def feed(feed_slug, user_id)
|
67
|
+
token = @signer.sign(feed_slug, user_id)
|
68
|
+
Stream::Feed.new(self, feed_slug, user_id, token)
|
89
69
|
end
|
90
70
|
|
91
|
-
|
71
|
+
def get_default_params
|
72
|
+
{ :api_key => @api_key }
|
73
|
+
end
|
92
74
|
|
93
|
-
|
94
|
-
|
75
|
+
def get_http_client
|
76
|
+
StreamHTTPClient.new(@api_version, @location, @default_timeout)
|
77
|
+
end
|
95
78
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
else
|
100
|
-
location_name = "#{location}-api"
|
101
|
-
end
|
102
|
-
@base_path = "/api/#{api_version}"
|
103
|
-
self.class.base_uri "https://#{location_name}.getstream.io#{@base_path}"
|
104
|
-
self.class.default_timeout default_timeout
|
105
|
-
end
|
79
|
+
def make_query_params(params)
|
80
|
+
get_default_params.merge(params)
|
81
|
+
end
|
106
82
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
83
|
+
def make_request(method, relative_url, signature, params = {}, data = {}, headers = {})
|
84
|
+
headers["Authorization"] = signature
|
85
|
+
get_http_client.make_http_request(method, relative_url, make_query_params(params), data, headers)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class StreamHTTPClient
|
90
|
+
include HTTParty
|
91
|
+
attr_reader :base_path
|
92
|
+
|
93
|
+
def initialize(api_version = "v1.0", location = nil, default_timeout = 3)
|
94
|
+
if location.nil?
|
95
|
+
location_name = "api"
|
96
|
+
else
|
97
|
+
location_name = "#{location}-api"
|
98
|
+
end
|
99
|
+
@base_path = "/api/#{api_version}"
|
100
|
+
self.class.base_uri "https://#{location_name}.getstream.io#{@base_path}"
|
101
|
+
self.class.default_timeout default_timeout
|
121
102
|
end
|
122
103
|
|
104
|
+
def make_http_request(method, relative_url, params = nil, data = nil, headers = nil)
|
105
|
+
headers["Content-Type"] = "application/json"
|
106
|
+
headers["X-Stream-Client"] = "stream-ruby-client-#{Stream::VERSION}"
|
107
|
+
body = data.to_json if ["post", "put"].include? method.to_s
|
108
|
+
response = self.class.send(method, relative_url, :headers => headers, :query => params, :body => body)
|
109
|
+
case response.code
|
110
|
+
when 200..203
|
111
|
+
return response
|
112
|
+
when 204...600
|
113
|
+
raise StreamApiResponseException, "#{response['exception']} details: #{response['detail']}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
123
117
|
end
|
data/lib/stream/exceptions.rb
CHANGED
data/lib/stream/feed.rb
CHANGED
@@ -1,127 +1,120 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require "stream/signer"
|
3
2
|
|
4
3
|
module Stream
|
4
|
+
class Feed
|
5
|
+
attr_reader :id
|
6
|
+
attr_reader :slug
|
7
|
+
attr_reader :user_id
|
8
|
+
attr_reader :token
|
9
|
+
attr_reader :signature
|
10
|
+
|
11
|
+
def initialize(client, feed_slug, user_id, token)
|
12
|
+
unless valid_feed_slug feed_slug
|
13
|
+
raise StreamInputData, "feed_slug can only contain alphanumeric characters"
|
14
|
+
end
|
15
|
+
|
16
|
+
unless valid_user_id user_id
|
17
|
+
raise StreamInputData, "user_id can only contain alphanumeric characters plus underscores and dashes"
|
18
|
+
end
|
19
|
+
|
20
|
+
@id = "#{feed_slug}:#{user_id}"
|
21
|
+
@client = client
|
22
|
+
@user_id = user_id
|
23
|
+
@slug = feed_slug
|
24
|
+
@feed_url = "#{feed_slug}/#{user_id}"
|
25
|
+
@token = token
|
26
|
+
@signature = "#{feed_slug}#{user_id} #{token}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def valid_feed_slug(feed_slug)
|
30
|
+
!feed_slug[/^[^_\W]+$/].nil?
|
31
|
+
end
|
5
32
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
def delete()
|
89
|
-
uri = "/feed/#{@feed_url}/"
|
90
|
-
@client.make_request(:delete, uri, @signature)
|
91
|
-
end
|
92
|
-
|
93
|
-
def follow(target_feed_slug, target_user_id)
|
94
|
-
uri = "/feed/#{@feed_url}/follows/"
|
95
|
-
follow_data = {
|
96
|
-
:target => "#{target_feed_slug}:#{target_user_id}",
|
97
|
-
:target_token => @client.feed(target_feed_slug, target_user_id).token
|
98
|
-
}
|
99
|
-
@client.make_request(:post, uri, @signature, {}, follow_data)
|
100
|
-
end
|
101
|
-
|
102
|
-
def followers(offset=0, limit=25)
|
103
|
-
uri = "/feed/#{@feed_url}/followers/"
|
104
|
-
params = {
|
105
|
-
'offset' => offset,
|
106
|
-
'limit' => limit
|
107
|
-
}
|
108
|
-
@client.make_request(:get, uri, @signature, params)
|
109
|
-
end
|
110
|
-
|
111
|
-
def following(offset=0, limit=25, filter=[])
|
112
|
-
uri = "/feed/#{@feed_url}/follows/"
|
113
|
-
params = {
|
114
|
-
'offset' => offset,
|
115
|
-
'limit' => limit,
|
116
|
-
'filter' => filter.join(",")
|
117
|
-
}
|
118
|
-
@client.make_request(:get, uri, @signature, params)
|
119
|
-
end
|
120
|
-
|
121
|
-
def unfollow(target_feed_slug, target_user_id)
|
122
|
-
uri = "/feed/#{@feed_url}/follows/#{target_feed_slug}:#{target_user_id}/"
|
123
|
-
@client.make_request(:delete, uri, @signature)
|
124
|
-
end
|
33
|
+
def valid_user_id(user_id)
|
34
|
+
!user_id.to_s[/^[\w-]+$/].nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def get(params = {})
|
38
|
+
uri = "/feed/#{@feed_url}/"
|
39
|
+
if params[:mark_read] && params[:mark_read].is_a?(Array)
|
40
|
+
params[:mark_read] = params[:mark_read].join(",")
|
41
|
+
end
|
42
|
+
if params[:mark_seen] && params[:mark_seen].is_a?(Array)
|
43
|
+
params[:mark_seen] = params[:mark_seen].join(",")
|
44
|
+
end
|
45
|
+
@client.make_request(:get, uri, @signature, params)
|
46
|
+
end
|
47
|
+
|
48
|
+
def sign_to_field(to)
|
49
|
+
to.map do |feed_id|
|
50
|
+
feed_slug, user_id = feed_id.split(":")
|
51
|
+
feed = @client.feed(feed_slug, user_id)
|
52
|
+
"#{feed.id} #{feed.token}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_activity(activity_data)
|
57
|
+
uri = "/feed/#{@feed_url}/"
|
58
|
+
activity_data[:to] &&= sign_to_field(activity_data[:to])
|
59
|
+
@client.make_request(:post, uri, @signature, {}, activity_data)
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_activities(activities)
|
63
|
+
uri = "/feed/#{@feed_url}/"
|
64
|
+
activities.each do |activity|
|
65
|
+
activity[:to] &&= sign_to_field(activity[:to])
|
66
|
+
end
|
67
|
+
data = { :activities => activities }
|
68
|
+
@client.make_request(:post, uri, @signature, {}, data)
|
69
|
+
end
|
70
|
+
|
71
|
+
def remove(activity_id, foreign_id = false)
|
72
|
+
remove_activity(activity_id, foreign_id)
|
73
|
+
end
|
74
|
+
|
75
|
+
def remove_activity(activity_id, foreign_id = false)
|
76
|
+
uri = "/feed/#{@feed_url}/#{activity_id}/"
|
77
|
+
params = {}
|
78
|
+
params = { "foreign_id" => 1 } if foreign_id
|
79
|
+
@client.make_request(:delete, uri, @signature, params)
|
80
|
+
end
|
81
|
+
|
82
|
+
def delete
|
83
|
+
uri = "/feed/#{@feed_url}/"
|
84
|
+
@client.make_request(:delete, uri, @signature)
|
85
|
+
end
|
86
|
+
|
87
|
+
def follow(target_feed_slug, target_user_id)
|
88
|
+
uri = "/feed/#{@feed_url}/follows/"
|
89
|
+
follow_data = {
|
90
|
+
:target => "#{target_feed_slug}:#{target_user_id}",
|
91
|
+
:target_token => @client.feed(target_feed_slug, target_user_id).token
|
92
|
+
}
|
93
|
+
@client.make_request(:post, uri, @signature, {}, follow_data)
|
94
|
+
end
|
95
|
+
|
96
|
+
def followers(offset = 0, limit = 25)
|
97
|
+
uri = "/feed/#{@feed_url}/followers/"
|
98
|
+
params = {
|
99
|
+
"offset" => offset,
|
100
|
+
"limit" => limit
|
101
|
+
}
|
102
|
+
@client.make_request(:get, uri, @signature, params)
|
103
|
+
end
|
104
|
+
|
105
|
+
def following(offset = 0, limit = 25, filter = [])
|
106
|
+
uri = "/feed/#{@feed_url}/follows/"
|
107
|
+
params = {
|
108
|
+
"offset" => offset,
|
109
|
+
"limit" => limit,
|
110
|
+
"filter" => filter.join(",")
|
111
|
+
}
|
112
|
+
@client.make_request(:get, uri, @signature, params)
|
113
|
+
end
|
125
114
|
|
115
|
+
def unfollow(target_feed_slug, target_user_id)
|
116
|
+
uri = "/feed/#{@feed_url}/follows/#{target_feed_slug}:#{target_user_id}/"
|
117
|
+
@client.make_request(:delete, uri, @signature)
|
126
118
|
end
|
119
|
+
end
|
127
120
|
end
|