brandspotter 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +20 -12
- data/lib/brandspotter/client.rb +12 -0
- data/lib/brandspotter/client/endpoints.rb +23 -0
- data/lib/brandspotter/client/jobs.rb +21 -0
- data/lib/brandspotter/version.rb +1 -1
- data/lib/misc/hash.rb +12 -0
- data/lib/misc/object.rb +10 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71a7612b26d3403b8ec7f271850d8893ad981af7
|
4
|
+
data.tar.gz: 8371df6a3edfd721bc1744432e598a6ad6bfd3cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b826af70df03199ec8024bfea35a21ce6345765739a5eb267ecba28ee62fbe17c5a6363593f8fcc945711f48dc4371ec53e960a2c1a7821bfd4c1fb759a0002
|
7
|
+
data.tar.gz: ddb08fac5157f0fd3469529a250f2f8a6a47a9f2cbe3d8ae6a36ee4ce0cf2873dbcef8363291d101460a6832730e325e0b4d21b2375e062dea91aa1955664ca7
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
# Brandspotter
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Sign up for your api credentials at: http://brandspotter.herokuapp.com
|
4
|
+
API is currently invitation only.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
9
8
|
Add this line to your application's Gemfile:
|
10
9
|
|
11
|
-
|
12
|
-
gem 'brandspotter'
|
13
|
-
```
|
10
|
+
gem ‘brandspotter’, '~> 0.1.0'
|
14
11
|
|
15
12
|
And then execute:
|
16
13
|
|
@@ -21,16 +18,27 @@ Or install it yourself as:
|
|
21
18
|
$ gem install brandspotter
|
22
19
|
|
23
20
|
## Usage
|
21
|
+
Create a new initializer: (config/initializers/brandspotter.rb)
|
24
22
|
|
25
|
-
|
23
|
+
Brandspotter.configure do |config|
|
24
|
+
config.user_token = ENV[‘brandspotter_user_token’]
|
25
|
+
end
|
26
26
|
|
27
|
-
## Development
|
28
27
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
28
|
|
31
|
-
|
29
|
+
## Methods
|
30
|
+
# create a new subscription
|
31
|
+
client = Brandspotter::Client.new
|
32
|
+
client.create_subscription(hashtag: 'hashtag')
|
32
33
|
|
33
|
-
|
34
|
+
# list all subscriptions
|
35
|
+
client = Brandspotter::Client.new
|
36
|
+
client.subscriptions
|
34
37
|
|
35
|
-
|
38
|
+
# find specific subscription
|
39
|
+
client = Brandspotter::Client.new
|
40
|
+
client.find_subscription(subscription_id)
|
36
41
|
|
42
|
+
# delete subscription
|
43
|
+
client = Brandspotter::Client.new
|
44
|
+
client.destroy_subscription(subscription_id)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path('../client/endpoints.rb', __FILE__)
|
2
|
+
require File.expand_path('../client/jobs.rb', __FILE__)
|
3
|
+
|
4
|
+
module Brandspotter
|
5
|
+
class Client
|
6
|
+
attr_accessor :user_token
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@user_token = Brandspotter.configuration.user_token
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Brandspotter
|
2
|
+
class Client
|
3
|
+
def base_uri(path='/')
|
4
|
+
"http://brandspotter.herokuapp.com/api#{path}?user_token=#{self.user_token}&"
|
5
|
+
end
|
6
|
+
|
7
|
+
def configure_payload(path, opts={})
|
8
|
+
base_uri(path) + opts.to_params
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_request(url)
|
12
|
+
JSON.parse RestClient::Request.execute(method: :get, url: url)
|
13
|
+
end
|
14
|
+
|
15
|
+
def post_request(path, opts)
|
16
|
+
JSON.parse RestClient.post(base_uri(path), opts)
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete_request(path)
|
20
|
+
JSON.parse RestClient::Request.execute(method: :delete, url: base_uri(path))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Brandspotter
|
2
|
+
class Client
|
3
|
+
|
4
|
+
def subscriptions
|
5
|
+
get_request configure_payload('/subscriptions')
|
6
|
+
end
|
7
|
+
|
8
|
+
def find_subscription(id)
|
9
|
+
get_request configure_payload("/subscriptions/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_subscription(opts={})
|
13
|
+
opts.assert_valid_keys(:hashtag)
|
14
|
+
post_request '/subscriptions', opts
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy_subscription(id)
|
18
|
+
delete_request "/subscriptions/#{id}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/brandspotter/version.rb
CHANGED
data/lib/misc/hash.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path('../object', __FILE__)
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
def assert_valid_keys(*valid_keys)
|
5
|
+
valid_keys.flatten!
|
6
|
+
each_key {|k| raise(ArgumentError, "Unknown key #{k}") unless valid_keys.include?(k)}
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_params
|
10
|
+
collect{|k, v| v.to_query(k)}.sort * '&'
|
11
|
+
end
|
12
|
+
end
|
data/lib/misc/object.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brandspotter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dirk van Wensem
|
@@ -68,7 +68,12 @@ files:
|
|
68
68
|
- bin/setup
|
69
69
|
- brandspotter.gemspec
|
70
70
|
- lib/brandspotter.rb
|
71
|
+
- lib/brandspotter/client.rb
|
72
|
+
- lib/brandspotter/client/endpoints.rb
|
73
|
+
- lib/brandspotter/client/jobs.rb
|
71
74
|
- lib/brandspotter/version.rb
|
75
|
+
- lib/misc/hash.rb
|
76
|
+
- lib/misc/object.rb
|
72
77
|
homepage: http://github.com/dennisdevulder/brandspotter
|
73
78
|
licenses: []
|
74
79
|
metadata: {}
|
@@ -88,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
93
|
version: '0'
|
89
94
|
requirements: []
|
90
95
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.5.1
|
92
97
|
signing_key:
|
93
98
|
specification_version: 4
|
94
99
|
summary: Implementation of the brandspotter API
|