stream-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +27 -0
- data/README.md +49 -0
- data/lib/stream.rb +1 -0
- data/lib/stream/base.rb +15 -0
- data/lib/stream/client.rb +20 -0
- data/lib/stream/feed.rb +76 -0
- data/lib/stream/signer.rb +23 -0
- data/lib/stream/version.rb +3 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c1225f2fbc4300a3dc90c9798396eec25fc1b46
|
4
|
+
data.tar.gz: 31c0a060ab08e8c6ef5dcdb5d42ef47d1cc2437d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c07f32235abbff7cd5883eabbb1583064fc7f4c7768ae3ade4df2472909fe20f61d979e12b309683fa7a2be06ae573cc321e3e6c3a3a057a0c72f07ece4abba8
|
7
|
+
data.tar.gz: 6fa48a3b8a86450a376c9e830670596946811df1feff3906cca9bb28909d173561fa61cd657b33453e22af5ce3f653f6c8a5b421f75631f3ce7340761edb389c
|
data/LICENSE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Copyright (c) 2014, Tommaso Barbugli
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
* Neither the name of the {organization} nor the names of its
|
15
|
+
contributors may be used to endorse or promote products derived from
|
16
|
+
this software without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
stream-ruby
|
2
|
+
=========
|
3
|
+
|
4
|
+
.. image:: https://circleci.com/gh/tbarbugli/stream-ruby.png
|
5
|
+
:target: https://circleci.com/gh/tbarbugli/stream-ruby.png/tree/master
|
6
|
+
|
7
|
+
|
8
|
+
stream-ruby is a Ruby client for `Stream <https://getstream.io/>`_.
|
9
|
+
|
10
|
+
.. code-block:: ruby
|
11
|
+
|
12
|
+
# Instantiate a new client
|
13
|
+
require 'stream'
|
14
|
+
client = Stream::Client.new('YOUR_API_KEY', 'API_KEY_SECRET')
|
15
|
+
|
16
|
+
# Instantiate a feed object
|
17
|
+
user_feed_1 = client.feed('user:1')
|
18
|
+
|
19
|
+
# Get activities from 5 to 10 (slow pagination)
|
20
|
+
result = user_feed_1.get(:limit=>5, :offset=>5)
|
21
|
+
# (Recommended & faster) Filter on an id less than 112334
|
22
|
+
result = user_feed_1.get(:limit=>5, :id_lt=>112334)
|
23
|
+
|
24
|
+
# Create a new activity
|
25
|
+
activity_data = {:actor => 1, :verb => 'tweet', :object => 1}
|
26
|
+
activity_response = user_feed_1.add_activity(activity_data)
|
27
|
+
|
28
|
+
# Remove an activity by its id
|
29
|
+
user_feed_1.remove('12345678910')
|
30
|
+
|
31
|
+
# Follow another feed
|
32
|
+
user_feed_1.follow('flat:42')
|
33
|
+
|
34
|
+
# Stop following another feed
|
35
|
+
user_feed_1.unfollow('flat:42')
|
36
|
+
|
37
|
+
|
38
|
+
Docs are available on `GetStream.io`_.
|
39
|
+
|
40
|
+
.. _GetStream.io: http://getstream.io/docs/
|
41
|
+
|
42
|
+
|
43
|
+
Installation
|
44
|
+
------------
|
45
|
+
|
46
|
+
.. code-block:: bash
|
47
|
+
|
48
|
+
gem "stream"
|
49
|
+
|
data/lib/stream.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'stream/base'
|
data/lib/stream/base.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'stream/client'
|
2
|
+
require 'stream/version'
|
3
|
+
require 'stream/signer'
|
4
|
+
|
5
|
+
module Stream
|
6
|
+
class << self
|
7
|
+
def connect(api_key, api_secret)
|
8
|
+
Stream::Client.new(api_key, api_secret)
|
9
|
+
end
|
10
|
+
|
11
|
+
def clean_feed_id(feed_id)
|
12
|
+
feed_id.sub(':', '')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'stream/signer'
|
2
|
+
require 'stream/feed'
|
3
|
+
|
4
|
+
module Stream
|
5
|
+
class Client
|
6
|
+
|
7
|
+
def initialize(api_key, api_secret)
|
8
|
+
@api_key = api_key
|
9
|
+
@api_secret = api_secret
|
10
|
+
@signer = Stream::Signer.new(api_secret)
|
11
|
+
end
|
12
|
+
|
13
|
+
def feed(feed_id)
|
14
|
+
cleaned_feed_id = Stream::clean_feed_id(feed_id)
|
15
|
+
signature = @signer.signature(cleaned_feed_id)
|
16
|
+
Stream::Feed.new(feed_id, @api_key, signature)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/stream/feed.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'stream/signer'
|
3
|
+
|
4
|
+
|
5
|
+
module Stream
|
6
|
+
|
7
|
+
class StreamHTTPClient
|
8
|
+
|
9
|
+
include HTTParty
|
10
|
+
base_uri 'https://getstream.io/api'
|
11
|
+
|
12
|
+
def make_http_request(method, relative_url, params=nil, data=nil, headers=nil)
|
13
|
+
response = self.class.send(method, relative_url, headers: headers, query: params, body: data)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
class Feed
|
19
|
+
@@http_client = nil
|
20
|
+
|
21
|
+
attr_reader :feed_id
|
22
|
+
|
23
|
+
def initialize(feed_id, api_key, signature)
|
24
|
+
@feed_id = Stream::clean_feed_id(feed_id)
|
25
|
+
@feed_url = feed_id.sub(':', '/')
|
26
|
+
@api_key = api_key
|
27
|
+
@auth_headers = {'Authorization' => "#{@feed_id} #{signature}"}
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_http_client
|
31
|
+
if @@http_client.nil?
|
32
|
+
@@http_client = StreamHTTPClient.new
|
33
|
+
end
|
34
|
+
@@http_client
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_default_params
|
38
|
+
{:api_key => @api_key}
|
39
|
+
end
|
40
|
+
|
41
|
+
def make_request(method, relative_url, params=nil, data=nil)
|
42
|
+
params = params.nil? ? {} : params
|
43
|
+
data = data.nil? ? {} : data
|
44
|
+
default_params = self.get_default_params
|
45
|
+
default_params.merge!(params)
|
46
|
+
self.get_http_client.make_http_request(method, relative_url, default_params, data, @auth_headers)
|
47
|
+
end
|
48
|
+
|
49
|
+
def get(params = {})
|
50
|
+
uri = "/feed/#{@feed_url}/"
|
51
|
+
self.make_request(:get, uri, params)
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_activity(activity_data)
|
55
|
+
uri = "/feed/#{@feed_url}/"
|
56
|
+
self.make_request(:post, uri, nil, activity_data)
|
57
|
+
end
|
58
|
+
|
59
|
+
def remove(activity_id)
|
60
|
+
uri = "/feed/#{@feed_url}/#{activity_id}/"
|
61
|
+
self.make_request(:delete, uri)
|
62
|
+
end
|
63
|
+
|
64
|
+
def follow(target_feed_id)
|
65
|
+
uri = "/feed/#{@feed_url}/follows/"
|
66
|
+
follow_data = {:target => target_feed_id}
|
67
|
+
self.make_request(:post, uri, nil, follow_data)
|
68
|
+
end
|
69
|
+
|
70
|
+
def unfollow(target_feed_id)
|
71
|
+
uri = "/feed/#{@feed_url}/follows/#{target_feed_id}/"
|
72
|
+
self.make_request(:delete, uri)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module Stream
|
5
|
+
class Signer
|
6
|
+
@key = nil
|
7
|
+
|
8
|
+
def initialize(key)
|
9
|
+
@key = key.to_s
|
10
|
+
@sha1 = OpenSSL::Digest::Digest.new('sha1')
|
11
|
+
end
|
12
|
+
|
13
|
+
def urlSafeB64encode(value)
|
14
|
+
value.gsub('+', '-').gsub('/', '_').gsub(/^=+/, '').gsub(/=+$/, '')
|
15
|
+
end
|
16
|
+
|
17
|
+
def signature(message)
|
18
|
+
key = Digest::SHA1.digest @key.to_s
|
19
|
+
signature = Base64.strict_encode64(OpenSSL::HMAC.digest(@sha1, key, message.to_s))
|
20
|
+
self.urlSafeB64encode(signature)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stream-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tommaso Barbugli
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.10'
|
55
|
+
description:
|
56
|
+
email: tbarbugli@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files:
|
60
|
+
- README.md
|
61
|
+
- LICENSE
|
62
|
+
files:
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- lib/stream.rb
|
66
|
+
- lib/stream/base.rb
|
67
|
+
- lib/stream/client.rb
|
68
|
+
- lib/stream/feed.rb
|
69
|
+
- lib/stream/signer.rb
|
70
|
+
- lib/stream/version.rb
|
71
|
+
homepage: http://github.com/tbarbugli/stream-ruby
|
72
|
+
licenses:
|
73
|
+
- Apache-2.0
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.2.2
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: A gem that provides a client interface for getstream.io
|
95
|
+
test_files: []
|