bwapi 1.0.0 → 1.0.1
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 +57 -5
- data/bwapi.gemspec +1 -0
- data/lib/bwapi/authentication.rb +6 -1
- data/lib/bwapi/configuration.rb +10 -6
- data/lib/bwapi/connection.rb +0 -1
- data/lib/bwapi/request.rb +9 -9
- data/lib/bwapi/version.rb +1 -1
- data/spec/bwapi/client_spec.rb +2 -2
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd2cf79cd157dd2ca6e76738c1424f1a47088df4
|
4
|
+
data.tar.gz: 1fac68af86ca4f7d8d210e2ca04614e53311b87d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11abad275db972f85bddf6d43dc398c255291ce65c70cc157755fe4fa1a5ffd711e053863cef5b0cbe1d8ca6e0a6d668c15587fa7a6b02f4b100588e93797860
|
7
|
+
data.tar.gz: a65bffa36df961516ac87aaf03566bab6439334df3bca2778ca263e255b7d14a0b56d34f7f2ce80570a64ec645a0c0bfca7e377511bdd03953b13f1e9a4af3d8
|
data/README.md
CHANGED
@@ -1,15 +1,67 @@
|
|
1
|
+
[](https://travis-ci.org/jonathanchrisp/bwapi)
|
2
|
+
[](https://gemnasium.com/jonathanchrisp/bwapi)
|
3
|
+
[](https://codeclimate.com/github/jonathanchrisp/bwapi)
|
4
|
+
|
1
5
|
# bwapi
|
2
6
|
|
3
7
|
__PLEASE NOTE THAT THIS PROJECT IS NOT OFFICIALLY SUPPORTED BY BRANDWATCH__
|
4
8
|
|
5
|
-
A Ruby interface to the Brandwatch
|
9
|
+
A Ruby interface to the Brandwatch V2 API. The projects design is modelled on the GitHub Octokit wrapper which can be found here: https://github.com/octokit/octokit.rb.
|
10
|
+
|
11
|
+
## Documentation
|
12
|
+
http://rubydoc.info/gems/bwapi/
|
13
|
+
|
14
|
+
## Getting Started
|
15
|
+
All Brandwatch API calls at present require you to be authenticated with the system. Therefore you'll need to create an instance of your client:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
bw = BWAPI::Client.new(:username => 'username@example.com', :password => 'pa$$w0rd')
|
19
|
+
```
|
20
|
+
|
21
|
+
Once you have your instance of your client you can then use a helper method to authenticate with Brandwatch:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
bw.login
|
25
|
+
```
|
26
|
+
|
27
|
+
The wrapper returns a boolean value to state whether you authenticated successfully.
|
28
|
+
|
29
|
+
## Example Requests
|
30
|
+
|
31
|
+
Once authenticated, you are then able to make additional requests. Please see a small selection of examples below:
|
32
|
+
|
33
|
+
### Get all projects
|
34
|
+
```ruby
|
35
|
+
bw.projects
|
36
|
+
=> #<Hashie::Mash results=[#<Hashie::Mash clientId=1856278873 clientName="JC BWAPI Demo" creationDate="2013-07-24T17:56:31.074+0000" creatorUserId=158304410 defaultIndustry="general-(recommended)" defaultLangCodes=["en"] description=nil id=1856280126 links=#<Hashie::Mash queries="http://newapi.brandwatch.com//projects/1856280126/queries.json?access_token=bd405bd7-9d1f-4c3d-ab5c-64b77791ae7f"> name="Demo Project">] resultsPage=-1 resultsPageSize=-1 resultsTotal=-1>
|
37
|
+
```
|
38
|
+
|
39
|
+
### Get a specific project
|
40
|
+
```ruby
|
41
|
+
bw.project 1856280126
|
42
|
+
=> #<Hashie::Mash clientId=1856278873 clientName="JC BWAPI Demo" creationDate="2013-07-24T17:56:31.074+0000" creatorUserId=158304410 defaultIndustry="general-(recommended)" defaultLangCodes=["en"] description=nil id=1856280126 links=#<Hashie::Mash queries="http://newapi.brandwatch.com//projects/1856280126/queries.json?access_token=bd405bd7-9d1f-4c3d-ab5c-64b77791ae7f"> name="Demo Project">
|
43
|
+
```
|
44
|
+
|
45
|
+
### Get a project queries summary
|
46
|
+
```ruby
|
47
|
+
bw.queries_summary 1856280126
|
48
|
+
=> #<Hashie::Mash results=[#<Hashie::Mash id=1856280351 name="LA Lakers">] resultsPage=-1 resultsPageSize=-1 resultsTotal=-1>
|
49
|
+
```
|
50
|
+
|
51
|
+
### Get user information
|
52
|
+
```ruby
|
53
|
+
bw.me
|
54
|
+
=> #<Hashie::Mash client=#<Hashie::Mash id=1856278873 name="JC BWAPI Demo" parentId=-1 railsEnabled=false theme="brandwatch"> firstName="BWAPI" id=158304410 lastName="Demo" links=#<Hashie::Mash logout="http://newapi.brandwatch.com/logout?access_token=bd405bd7-9d1f-4c3d-ab5c-64b77791ae7f" user="http://newapi.brandwatch.com//user.json?access_token=bd405bd7-9d1f-4c3d-ab5c-64b77791ae7f"> tags=#<Hashie::Mash notify="true"> uiRole="admin" username="bwapi_demo=jonathan@brandwatch.com">
|
55
|
+
```
|
6
56
|
|
7
57
|
## Tests
|
8
|
-
There are a number of unit tests which are included as part of this project
|
58
|
+
There are a number of unit tests which are included as part of this project, please run:
|
9
59
|
|
10
|
-
|
60
|
+
```ruby
|
61
|
+
rspec spec
|
62
|
+
```
|
11
63
|
|
12
|
-
Please note that a number of tests still need to be added so I don't currently have complete coverage.
|
64
|
+
Please note that a number of tests still need to be added so I don't currently have complete coverage, subject to workload these will be slowly added over the next few months.
|
13
65
|
|
14
66
|
## Feedback
|
15
|
-
I would be more than happy to recieve feedback, please email me at: jonathan.chrisp@gmail.com
|
67
|
+
I would be more than happy to recieve feedback, please email me at: jonathan.chrisp@gmail.com or jonathan@brandwatch.com
|
data/bwapi.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_runtime_dependency 'faraday', '~> 0.8.7'
|
19
19
|
s.add_runtime_dependency 'faraday_middleware', '~> 0.9.0'
|
20
20
|
s.add_runtime_dependency 'netrc', '~> 0.7.7'
|
21
|
+
s.add_runtime_dependency 'colored', '~> 1.2'
|
21
22
|
|
22
23
|
s.files = `git ls-files`.split("\n")
|
23
24
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/lib/bwapi/authentication.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'colored'
|
2
2
|
|
3
3
|
module BWAPI
|
4
4
|
module Authentication
|
@@ -29,13 +29,18 @@ module BWAPI
|
|
29
29
|
# @param netrc [Boolean] Netrc status
|
30
30
|
def netrc_credentials netrc=false
|
31
31
|
return unless netrc
|
32
|
+
|
33
|
+
require 'netrc'
|
32
34
|
file = Netrc.read netrc_file
|
33
35
|
|
34
36
|
# Get credentials using host
|
35
37
|
netrc_host = URI.parse(api_endpoint).host
|
36
38
|
creds = file[netrc_host]
|
39
|
+
raise 'You are missing your .netrc file or the host provided has no credentials!'.red.underline if creds.nil?
|
37
40
|
self.username = creds.shift
|
38
41
|
self.password = creds.shift
|
42
|
+
rescue LoadError
|
43
|
+
raise "Please install netrc gem for .netrc support".red.underline
|
39
44
|
end
|
40
45
|
|
41
46
|
end
|
data/lib/bwapi/configuration.rb
CHANGED
@@ -15,12 +15,13 @@ module BWAPI
|
|
15
15
|
:expires_in,
|
16
16
|
:client_id,
|
17
17
|
:client_secret,
|
18
|
+
:verify_ssl,
|
18
19
|
:netrc,
|
19
20
|
:netrc_file
|
20
21
|
].freeze
|
21
22
|
|
22
23
|
DEFAULT_ADAPTER = Faraday.default_adapter
|
23
|
-
DEFAULT_API_ENDPOINT =
|
24
|
+
DEFAULT_API_ENDPOINT = 'https://newapi.brandwatch.com/'
|
24
25
|
DEFAULT_CLIENT_ID = 'brandwatch-api-client'
|
25
26
|
DEFAULT_USER_AGENT = "BWAPI Ruby Gem #{BWAPI::VERSION}".freeze
|
26
27
|
DEFAULT_NETRC_FILE = File.join(ENV['HOME'], '.netrc')
|
@@ -32,15 +33,12 @@ module BWAPI
|
|
32
33
|
base.reset
|
33
34
|
end
|
34
35
|
|
36
|
+
# Set configuration options using a block
|
35
37
|
def configure
|
36
38
|
yield self
|
37
39
|
end
|
38
40
|
|
39
|
-
#
|
40
|
-
def options
|
41
|
-
OPTION_KEYS.inject({}){|o,k|o.merge!(k => send(k))}
|
42
|
-
end
|
43
|
-
|
41
|
+
# Reset the configuration options
|
44
42
|
def reset
|
45
43
|
self.adapter = DEFAULT_ADAPTER
|
46
44
|
self.user_agent = DEFAULT_USER_AGENT
|
@@ -52,8 +50,14 @@ module BWAPI
|
|
52
50
|
self.refresh_token = nil
|
53
51
|
self.client_id = DEFAULT_CLIENT_ID
|
54
52
|
self.client_secret = nil
|
53
|
+
self.verify_ssl = true
|
55
54
|
self.netrc = false
|
56
55
|
self.netrc_file = DEFAULT_NETRC_FILE
|
57
56
|
end
|
57
|
+
|
58
|
+
# Convert option_keys to hash and return
|
59
|
+
def options
|
60
|
+
OPTION_KEYS.inject({}){|o,k|o.merge!(k => send(k))}
|
61
|
+
end
|
58
62
|
end
|
59
63
|
end
|
data/lib/bwapi/connection.rb
CHANGED
data/lib/bwapi/request.rb
CHANGED
@@ -57,19 +57,19 @@ module BWAPI
|
|
57
57
|
# @param opts [Hash] Request parameters
|
58
58
|
# @return [Hashie::Mash] Response
|
59
59
|
def request method, path, opts={}
|
60
|
-
token = access_token
|
61
|
-
|
62
|
-
force_urlencoded = opts.delete(:force_urlencoded) || false
|
63
|
-
|
64
60
|
conn_opts = {
|
65
|
-
:
|
66
|
-
|
61
|
+
:headers => {
|
62
|
+
:user_agent => user_agent
|
63
|
+
},
|
64
|
+
:force_urlencoded => opts.delete(:force_urlencoded) || false,
|
65
|
+
:url => api_endpoint,
|
66
|
+
:ssl => {:verify => verify_ssl}
|
67
67
|
}
|
68
68
|
|
69
69
|
response = connection(conn_opts).send(method) do |request|
|
70
70
|
# Add token to the header
|
71
|
-
if
|
72
|
-
request.headers[:authorization] = "bearer #{
|
71
|
+
if access_token
|
72
|
+
request.headers[:authorization] = "bearer #{access_token}"
|
73
73
|
end
|
74
74
|
|
75
75
|
case method
|
@@ -78,7 +78,7 @@ module BWAPI
|
|
78
78
|
when :delete
|
79
79
|
request.url path, opts
|
80
80
|
when :patch, :post, :put
|
81
|
-
if force_urlencoded
|
81
|
+
if conn_opts[:force_urlencoded]
|
82
82
|
request.url path, opts
|
83
83
|
else
|
84
84
|
request.path = path
|
data/lib/bwapi/version.rb
CHANGED
data/spec/bwapi/client_spec.rb
CHANGED
@@ -117,8 +117,8 @@ describe BWAPI::Client do
|
|
117
117
|
expect(BWAPI::Client.new.netrc).to eql(false)
|
118
118
|
end
|
119
119
|
|
120
|
-
it 'should allow a user to set
|
121
|
-
bw = BWAPI::Client.new :netrc => true
|
120
|
+
it 'should allow a user to set true for the netrc value' do
|
121
|
+
bw = BWAPI::Client.new :netrc => true, :netrc_file => File.join(fixture_path, '.netrc')
|
122
122
|
expect(bw.netrc).to eql(true)
|
123
123
|
end
|
124
124
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bwapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Chrisp
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.7.7
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: colored
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.2'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.2'
|
83
97
|
description: A Ruby wrapper for the Brandwatch v2 API
|
84
98
|
email: jonathan@brandwatch.com
|
85
99
|
executables:
|
@@ -176,3 +190,4 @@ test_files:
|
|
176
190
|
- spec/bwapi_spec.rb
|
177
191
|
- spec/fixtures/.netrc
|
178
192
|
- spec/helper.rb
|
193
|
+
has_rdoc:
|