cognitivebing 0.2.0 → 0.2.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/.gitignore +9 -9
- data/.project +18 -12
- data/.travis.yml +4 -4
- data/CODE_OF_CONDUCT.md +13 -13
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +62 -57
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +7 -7
- data/cognitivebing.gemspec +33 -33
- data/lib/cognitivebing.rb +169 -80
- data/lib/cognitivebing/version.rb +3 -3
- metadata +3 -4
- data/lib/cognitivebingnews.rb +0 -93
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04682a05db10c57761f663d1044f77da48fedc31
|
4
|
+
data.tar.gz: 746d54039a565bd7ac68be65e8a8aef46223b236
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0e8d07da9c99e6bcc48da47e7ba065159f05e2ccc2e1defaa05c5a2bb1bcee61f111839eec8d5976b24aa8e4adc56e8cbbc62d67a342e3e3d3c9cf195a68b25
|
7
|
+
data.tar.gz: 5670cf02789d4b6cf21da2609e0165c784e5286fc12f5b2e8e2caae41810f87e1969e6e9fa6b55b156eb615944cfe7c0d05324581d5ae5634432b8cf744d83c3
|
data/.gitignore
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
data/.project
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<projectDescription>
|
3
|
-
<name>cognitivebing</name>
|
4
|
-
<comment></comment>
|
5
|
-
<projects>
|
6
|
-
</projects>
|
7
|
-
<buildSpec>
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
</
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>cognitivebing</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>com.aptana.ide.core.unifiedBuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>com.aptana.projects.webnature</nature>
|
16
|
+
<nature>com.aptana.ruby.core.rubynature</nature>
|
17
|
+
</natures>
|
18
|
+
</projectDescription>
|
data/.travis.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.1.0
|
4
|
-
before_install: gem install bundler -v 1.10.6
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1.0
|
4
|
+
before_install: gem install bundler -v 1.10.6
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
-
|
5
|
-
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
-
|
7
|
-
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
-
|
9
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
-
|
11
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
-
|
13
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in cognitivebing.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in cognitivebing.gemspec
|
4
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2016 aggounix
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 aggounix
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,57 +1,62 @@
|
|
1
|
-
# Cognitivebing
|
2
|
-
|
3
|
-
A gem for the new Bing Web Search API from Microsoft cognitive services.
|
4
|
-
|
5
|
-
https://www.microsoft.com/cognitive-services/en-us/apis
|
6
|
-
|
7
|
-
|
8
|
-
## Installation
|
9
|
-
|
10
|
-
Add this line to your application's Gemfile:
|
11
|
-
|
12
|
-
```ruby
|
13
|
-
gem 'cognitivebing'
|
14
|
-
```
|
15
|
-
|
16
|
-
And then execute:
|
17
|
-
|
18
|
-
$ bundle
|
19
|
-
|
20
|
-
Or install it yourself as:
|
21
|
-
|
22
|
-
$ gem install cognitivebing
|
23
|
-
|
24
|
-
## Usage
|
25
|
-
|
26
|
-
require 'cognitivebing'
|
27
|
-
|
28
|
-
bing = CognitiveBing.new(account_key)
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
result_set = bing.search(search_term)
|
40
|
-
#
|
41
|
-
result_set = bing.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
##
|
55
|
-
|
56
|
-
|
57
|
-
|
1
|
+
# Cognitivebing
|
2
|
+
|
3
|
+
A gem for the new Bing Web Search API from Microsoft cognitive services.
|
4
|
+
|
5
|
+
https://www.microsoft.com/cognitive-services/en-us/apis
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'cognitivebing'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install cognitivebing
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
require 'cognitivebing'
|
27
|
+
|
28
|
+
bing = CognitiveBing.new(account_key)
|
29
|
+
#call with params
|
30
|
+
bing = CognitiveBing.new(account_key, :mkt => "en-US", :count => 10, :offset => 0, :safesearch => "Moderate")
|
31
|
+
|
32
|
+
|
33
|
+
(to see params details : https://dev.cognitive.microsoft.com/docs/services/56b43eeccf5ff8098cef3807/operations/56b4447dcf5ff8098cef380d)
|
34
|
+
#web search
|
35
|
+
result_set = bing.search(search_term)
|
36
|
+
#Image search
|
37
|
+
result_set = bing.search(search_term, 'image')
|
38
|
+
#Video search
|
39
|
+
result_set = bing.search(search_term, 'videos')
|
40
|
+
#Suggestion search
|
41
|
+
result_set = bing.suggestions(search_term)
|
42
|
+
#News search
|
43
|
+
bing = CognitiveBingNews.new(account_key)
|
44
|
+
result_set = bing.search(search_term)
|
45
|
+
#News trending
|
46
|
+
result_set = bing.trending
|
47
|
+
|
48
|
+
## Development
|
49
|
+
|
50
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
51
|
+
|
52
|
+
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).
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cognitivebing. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
57
|
+
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
62
|
+
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rake/testtask"
|
3
|
-
|
4
|
-
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs << "test"
|
6
|
-
t.libs << "lib"
|
7
|
-
t.test_files = FileList['test/**/*_test.rb']
|
8
|
-
end
|
9
|
-
|
10
|
-
task :default => :test
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :test
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "cognitivebing"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cognitivebing"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
|
5
|
-
bundle install
|
6
|
-
|
7
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/bin/bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
|
5
|
+
bundle install
|
6
|
+
|
7
|
+
# Do any other automated setup that you need to do here
|
data/cognitivebing.gemspec
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'cognitivebing/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "cognitivebing"
|
8
|
-
spec.version = Cognitivebing::VERSION
|
9
|
-
spec.authors = ["aggounix"]
|
10
|
-
spec.email = ["melaggouni@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{Query New Cognitive Bing APIs.}
|
13
|
-
spec.description = %q{Query New Cognitive Bing APIs.}
|
14
|
-
spec.homepage = "https://github.com/aggounix/cognitivebing"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
#if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
#else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
#end
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
spec.bindir = "exe"
|
27
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = ["lib"]
|
29
|
-
|
30
|
-
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
-
spec.add_development_dependency "minitest"
|
33
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cognitivebing/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cognitivebing"
|
8
|
+
spec.version = Cognitivebing::VERSION
|
9
|
+
spec.authors = ["aggounix"]
|
10
|
+
spec.email = ["melaggouni@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Query New Cognitive Bing APIs.}
|
13
|
+
spec.description = %q{Query New Cognitive Bing APIs.}
|
14
|
+
spec.homepage = "https://github.com/aggounix/cognitivebing"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
#if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
#else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
#end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "minitest"
|
33
|
+
end
|
data/lib/cognitivebing.rb
CHANGED
@@ -1,80 +1,169 @@
|
|
1
|
-
require "cognitivebing/version"
|
2
|
-
require 'json'
|
3
|
-
require 'open-uri'
|
4
|
-
require 'net/http'
|
5
|
-
|
6
|
-
class CognitiveBing
|
7
|
-
attr_accessor :account_key, :params
|
8
|
-
|
9
|
-
def initialize(account_key, params = {})
|
10
|
-
@account_key = account_key
|
11
|
-
@params = params
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
def search(search_term, type = 'web')
|
16
|
-
|
17
|
-
|
18
|
-
query_string = '?q='
|
19
|
-
query_portion = URI.encode_www_form_component('\'' + search_term + '\'')
|
20
|
-
params = "&Ocp-Apim-Subscription-Key=#{@account_key}"
|
21
|
-
@params.each do |k,v|
|
22
|
-
params << "&#{k.to_s}=#{v.to_s}"
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
web_search_url = ""
|
27
|
-
|
28
|
-
if type == "videos"
|
29
|
-
web_search_url = "https://api.cognitive.microsoft.com/bing/v5.0/videos/search"
|
30
|
-
elsif type == "image"
|
31
|
-
web_search_url = "https://api.cognitive.microsoft.com/bing/v5.0/images/search"
|
32
|
-
else
|
33
|
-
web_search_url = "https://api.cognitive.microsoft.com/bing/v5.0/search"
|
34
|
-
end
|
35
|
-
|
36
|
-
full_address = web_search_url + query_string + query_portion + params
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
req
|
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
|
-
req
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
1
|
+
require "cognitivebing/version"
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
class CognitiveBing
|
7
|
+
attr_accessor :account_key, :params
|
8
|
+
|
9
|
+
def initialize(account_key, params = {})
|
10
|
+
@account_key = account_key
|
11
|
+
@params = params
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def search(search_term, type = 'web')
|
16
|
+
|
17
|
+
|
18
|
+
query_string = '?q='
|
19
|
+
query_portion = URI.encode_www_form_component('\'' + search_term + '\'')
|
20
|
+
params = "&Ocp-Apim-Subscription-Key=#{@account_key}"
|
21
|
+
@params.each do |k,v|
|
22
|
+
params << "&#{k.to_s}=#{v.to_s}"
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
web_search_url = ""
|
27
|
+
|
28
|
+
if type == "videos"
|
29
|
+
web_search_url = "https://api.cognitive.microsoft.com/bing/v5.0/videos/search"
|
30
|
+
elsif type == "image"
|
31
|
+
web_search_url = "https://api.cognitive.microsoft.com/bing/v5.0/images/search"
|
32
|
+
else
|
33
|
+
web_search_url = "https://api.cognitive.microsoft.com/bing/v5.0/search"
|
34
|
+
end
|
35
|
+
|
36
|
+
full_address = web_search_url + query_string + query_portion + params
|
37
|
+
|
38
|
+
uri = URI(full_address)
|
39
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
40
|
+
req.add_field("Ocp-Apim-Subscription-Key", @account_key)
|
41
|
+
|
42
|
+
|
43
|
+
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https'){|http|
|
44
|
+
http.request(req)
|
45
|
+
}
|
46
|
+
|
47
|
+
body = JSON.parse(res.body, :symbolize_names => true)
|
48
|
+
|
49
|
+
|
50
|
+
return body
|
51
|
+
end
|
52
|
+
|
53
|
+
def suggestions(search_term)
|
54
|
+
|
55
|
+
|
56
|
+
query_string = '?q='
|
57
|
+
query_portion = URI.encode_www_form_component( search_term )
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
web_search_url = "https://api.cognitive.microsoft.com/bing/v5.0/suggestions"
|
62
|
+
|
63
|
+
full_address = web_search_url + query_string + query_portion
|
64
|
+
|
65
|
+
uri = URI(full_address)
|
66
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
67
|
+
req.add_field("Ocp-Apim-Subscription-Key", @account_key)
|
68
|
+
|
69
|
+
|
70
|
+
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https'){|http|
|
71
|
+
http.request(req)
|
72
|
+
}
|
73
|
+
|
74
|
+
body = JSON.parse(res.body, :symbolize_names => true)
|
75
|
+
|
76
|
+
|
77
|
+
return body
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
class CognitiveBingNews
|
83
|
+
attr_accessor :account_key
|
84
|
+
|
85
|
+
def initialize(account_key, params = {})
|
86
|
+
@account_key = account_key
|
87
|
+
@params = params
|
88
|
+
end
|
89
|
+
|
90
|
+
def search(search_term)
|
91
|
+
|
92
|
+
|
93
|
+
query_string = '?q='
|
94
|
+
query_portion = URI.encode_www_form_component('\'' + search_term + '\'')
|
95
|
+
paramsbuilder = "&Ocp-Apim-Subscription-Key=#{@account_key}"
|
96
|
+
@params.each do |k,v|
|
97
|
+
paramsbuilder << "&#{k.to_s}=#{v.to_s}"
|
98
|
+
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
web_search_url = "https://api.cognitive.microsoft.com/bing/v5.0/news/search"
|
103
|
+
|
104
|
+
|
105
|
+
full_address = web_search_url + query_string + query_portion + paramsbuilder
|
106
|
+
puts full_address
|
107
|
+
|
108
|
+
uri = URI(full_address)
|
109
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
110
|
+
req.add_field("Ocp-Apim-Subscription-Key", @account_key)
|
111
|
+
|
112
|
+
|
113
|
+
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https'){|http|
|
114
|
+
http.request(req)
|
115
|
+
}
|
116
|
+
|
117
|
+
body = JSON.parse(res.body, :symbolize_names => true)
|
118
|
+
|
119
|
+
|
120
|
+
return body
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
def category(category_term, params = {})
|
126
|
+
|
127
|
+
web_search_url = URI('https://api.cognitive.microsoft.com/bing/v5.0/news/')
|
128
|
+
web_search_url.query = URI.encode_www_form({
|
129
|
+
# Request parameters
|
130
|
+
'category' => '#{category_term}'
|
131
|
+
})
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
uri = URI(web_search_url)
|
136
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
137
|
+
req.add_field("Ocp-Apim-Subscription-Key", @account_key)
|
138
|
+
|
139
|
+
|
140
|
+
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https'){|http|
|
141
|
+
http.request(req)
|
142
|
+
}
|
143
|
+
|
144
|
+
body = JSON.parse(res.body, :symbolize_names => true)
|
145
|
+
|
146
|
+
|
147
|
+
return body
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
def trending
|
152
|
+
|
153
|
+
web_search_url = "https://api.cognitive.microsoft.com/bing/v5.0/news/trendingtopics"
|
154
|
+
|
155
|
+
|
156
|
+
uri = URI(web_search_url)
|
157
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
158
|
+
req.add_field("Ocp-Apim-Subscription-Key", @account_key)
|
159
|
+
|
160
|
+
|
161
|
+
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https'){|http|
|
162
|
+
http.request(req)
|
163
|
+
}
|
164
|
+
|
165
|
+
body = JSON.parse(res.body, :symbolize_names => true)
|
166
|
+
|
167
|
+
return body
|
168
|
+
end
|
169
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module Cognitivebing
|
2
|
-
VERSION = "0.2.
|
3
|
-
end
|
1
|
+
module Cognitivebing
|
2
|
+
VERSION = "0.2.1"
|
3
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cognitivebing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aggounix
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,7 +72,6 @@ files:
|
|
72
72
|
- cognitivebing.gemspec
|
73
73
|
- lib/cognitivebing.rb
|
74
74
|
- lib/cognitivebing/version.rb
|
75
|
-
- lib/cognitivebingnews.rb
|
76
75
|
homepage: https://github.com/aggounix/cognitivebing
|
77
76
|
licenses:
|
78
77
|
- MIT
|
@@ -93,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
92
|
version: '0'
|
94
93
|
requirements: []
|
95
94
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.4.
|
95
|
+
rubygems_version: 2.4.5.1
|
97
96
|
signing_key:
|
98
97
|
specification_version: 4
|
99
98
|
summary: Query New Cognitive Bing APIs.
|
data/lib/cognitivebingnews.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
require "cognitivebing/version"
|
2
|
-
require 'json'
|
3
|
-
require 'open-uri'
|
4
|
-
require 'net/http'
|
5
|
-
|
6
|
-
|
7
|
-
class CognitiveBingNews
|
8
|
-
attr_accessor :account_key
|
9
|
-
|
10
|
-
def initialize(account_key, params = {})
|
11
|
-
@account_key = account_key
|
12
|
-
end
|
13
|
-
|
14
|
-
def search(search_term, params)
|
15
|
-
|
16
|
-
|
17
|
-
query_string = '?q='
|
18
|
-
query_portion = URI.encode_www_form_component('\'' + search_term + '\'')
|
19
|
-
paramsbuilder = "&Ocp-Apim-Subscription-Key=#{@account_key}"
|
20
|
-
params.each do |k,v|
|
21
|
-
paramsbuilder << "&#{k.to_s}=#{v.to_s}"
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
web_search_url = "https://api.cognitive.microsoft.com/bing/v5.0/news/search"
|
27
|
-
|
28
|
-
|
29
|
-
full_address = web_search_url + query_string + query_portion + paramsbuilder
|
30
|
-
puts full_address
|
31
|
-
|
32
|
-
uri = URI(full_address)
|
33
|
-
req = Net::HTTP::Get.new(uri.request_uri)
|
34
|
-
req.add_field("Ocp-Apim-Subscription-Key", @account_key)
|
35
|
-
|
36
|
-
|
37
|
-
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https'){|http|
|
38
|
-
http.request(req)
|
39
|
-
}
|
40
|
-
|
41
|
-
body = JSON.parse(res.body, :symbolize_names => true)
|
42
|
-
|
43
|
-
|
44
|
-
return body
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
def category(category_term, params = {})
|
50
|
-
|
51
|
-
web_search_url = URI('https://api.cognitive.microsoft.com/bing/v5.0/news/')
|
52
|
-
web_search_url.query = URI.encode_www_form({
|
53
|
-
# Request parameters
|
54
|
-
'category' => '#{category_term}'
|
55
|
-
})
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
uri = URI(web_search_url)
|
60
|
-
req = Net::HTTP::Get.new(uri.request_uri)
|
61
|
-
req.add_field("Ocp-Apim-Subscription-Key", @account_key)
|
62
|
-
|
63
|
-
|
64
|
-
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https'){|http|
|
65
|
-
http.request(req)
|
66
|
-
}
|
67
|
-
|
68
|
-
body = JSON.parse(res.body, :symbolize_names => true)
|
69
|
-
|
70
|
-
|
71
|
-
return body
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
def trending
|
76
|
-
|
77
|
-
web_search_url = "https://api.cognitive.microsoft.com/bing/v5.0/news/trendingtopics"
|
78
|
-
|
79
|
-
|
80
|
-
uri = URI(web_search_url)
|
81
|
-
req = Net::HTTP::Get.new(uri.request_uri)
|
82
|
-
req.add_field("Ocp-Apim-Subscription-Key", @account_key)
|
83
|
-
|
84
|
-
|
85
|
-
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https'){|http|
|
86
|
-
http.request(req)
|
87
|
-
}
|
88
|
-
|
89
|
-
body = JSON.parse(res.body, :symbolize_names => true)
|
90
|
-
|
91
|
-
return body
|
92
|
-
end
|
93
|
-
end
|