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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01ba22ee63e79e02d6518f1b203f42b1d1c19977
4
- data.tar.gz: 0a934487301b64e3239146bf8ca7af58d4fe5b2f
3
+ metadata.gz: 71a7612b26d3403b8ec7f271850d8893ad981af7
4
+ data.tar.gz: 8371df6a3edfd721bc1744432e598a6ad6bfd3cd
5
5
  SHA512:
6
- metadata.gz: 701321abe62ce7b3c853cc97a3ef0e2c7836578e7ae3c509371f79c687dd118294438ac1c4f0762214964b7854981d20eca3e9e24b71456c15ba8ad85f075931
7
- data.tar.gz: ad0e7743f14ab4c08b8c92cc9476bcfacb97aabe723e5497dfbcd1e5dd5a025aa89e8ba543f7e00efd7c676765b7232533257f2db2aa3b87079f7dcaaaaad254
6
+ metadata.gz: 4b826af70df03199ec8024bfea35a21ce6345765739a5eb267ecba28ee62fbe17c5a6363593f8fcc945711f48dc4371ec53e960a2c1a7821bfd4c1fb759a0002
7
+ data.tar.gz: ddb08fac5157f0fd3469529a250f2f8a6a47a9f2cbe3d8ae6a36ee4ce0cf2873dbcef8363291d101460a6832730e325e0b4d21b2375e062dea91aa1955664ca7
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .DS_Store
data/README.md CHANGED
@@ -1,16 +1,13 @@
1
1
  # Brandspotter
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/brandspotter`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- ```ruby
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
- TODO: Write usage instructions here
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
29
+ ## Methods
30
+ # create a new subscription
31
+ client = Brandspotter::Client.new
32
+ client.create_subscription(hashtag: 'hashtag')
32
33
 
33
- ## Contributing
34
+ # list all subscriptions
35
+ client = Brandspotter::Client.new
36
+ client.subscriptions
34
37
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/brandspotter.
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
@@ -1,3 +1,3 @@
1
1
  module Brandspotter
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
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
@@ -0,0 +1,10 @@
1
+ class Object
2
+ def to_param
3
+ to_s
4
+ end
5
+
6
+ def to_query(key)
7
+ require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
8
+ "#{CGI.escape(key.to_s).gsub(/%(5B|5D)/n) { [$1].pack('H*') }}=#{CGI.escape(to_param.to_s)}"
9
+ end
10
+ end
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: 0.1.0
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.4.6
96
+ rubygems_version: 2.5.1
92
97
  signing_key:
93
98
  specification_version: 4
94
99
  summary: Implementation of the brandspotter API