google-csene 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e11c5e2c5aac89691549fab2356ddbaf6557216
4
+ data.tar.gz: ac667dd485e2171fe25e802996166c0f78d24e00
5
+ SHA512:
6
+ metadata.gz: f8db920ee02bb623ad5c61db253dbbd9d3ef8882e36284e73dbc88a135fd6e77c8bed29ba886d1168108bee4a38eec1938c049b1f3e3d8f7f77a5975efecb1fa
7
+ data.tar.gz: 2abdf93326635f70d6a0d8825e575e08233b8af9c78b19e3fed16e3fceeda0d4f5e0a4fc950a15e2adafd2d90d083870122d4a293db2ecb07664f38c2a0e7132
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +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, 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 ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in google-csene.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Hirofumi Wakasugi
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 ADDED
@@ -0,0 +1,50 @@
1
+ # Google::Csene
2
+
3
+ Easy to get some Google CSE results including search ranks and index count.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'google-csene'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ``` text
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ``` text
22
+ $ gem install google-csene
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ __Getting Search ranks__
28
+
29
+ ```ruby
30
+ client = Google::SearchRank.new(api_key: "xxxx", cse_id: "xxxx")
31
+ rank = client.find("KEYWORD", %r{http://example.com/.*})
32
+ ```
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it ( https://github.com/5t111111/google-csene/fork )
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create a new Pull Request
47
+
48
+ ## Thanks
49
+
50
+ [google-search_rank](https://github.com/komagata/google-search_rank)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "google/cse"
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 ADDED
@@ -0,0 +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
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'google/csene/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "google-csene"
7
+ spec.version = Google::Csene::VERSION
8
+ spec.authors = ['Hirofumi Wakasugi']
9
+ spec.email = ["komagata@gmail.com"]
10
+
11
+ spec.summary = %q{Easy to get some Google CSE results including search ranks and index count.}
12
+ spec.description = %q{Easy to get some Google CSE results including search ranks and index count.}
13
+ spec.homepage = "https://github.com/5t111111/google-csene"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "google-api-client", "~> 0.8.6"
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,3 @@
1
+ require 'google/csene/version'
2
+ require 'google/api_client'
3
+ require 'google/csene/client'
@@ -0,0 +1,78 @@
1
+ module Google
2
+ module Csene
3
+ class Client
4
+ TOKEN_CREDENTIAL_URI = 'https://accounts.google.com/o/oauth2/token'
5
+ AUDIENCE = 'https://accounts.google.com/o/oauth2/token'
6
+ SCOPE = 'https://www.googleapis.com/auth/cse'
7
+
8
+ def initialize(application_name: 'google-csene',
9
+ application_version: '1.0',
10
+ api_key:,
11
+ cse_id:)
12
+ @application_name = application_name
13
+ @application_version = application_version
14
+ @api_key = api_key
15
+ @cse_id = cse_id
16
+ end
17
+
18
+ def client
19
+ @client ||= Google::APIClient.new(
20
+ application_name: @application_name,
21
+ application_version: @application_version,
22
+ authorization: nil
23
+ )
24
+ end
25
+
26
+ def page_rank(site, link, page = 1)
27
+ start = (page - 1) * 10 + 1
28
+ result = client.execute(
29
+ service.cse.list,
30
+ default_options.merge(
31
+ 'start' => start,
32
+ 'q' => site
33
+ )
34
+ )
35
+ queries = result.data.queries
36
+ has_next_page = !queries.nil? && queries['nextPage'].count > 0
37
+ has_result = result.data.items.count > 0
38
+
39
+ return 0 unless has_result
40
+
41
+ result.data.items.each_with_index do |item, i|
42
+ # puts "start: #{start}, i: #{i} rank: #{start + i}, query: #{site}, link: #{item.link}"
43
+ if item.link =~ link
44
+ return start + i
45
+ elsif item.link == link
46
+ return start + i
47
+ end
48
+ end
49
+
50
+ page_rank(site, link, page + 1) if has_next_page
51
+ end
52
+
53
+ def index_count(site)
54
+ result = client.execute(
55
+ service.cse.list,
56
+ default_options.merge(
57
+ 'q' => "site:#{site}"
58
+ )
59
+ )
60
+
61
+ result.data.search_information.total_results
62
+ end
63
+
64
+ private
65
+
66
+ def default_options
67
+ {
68
+ 'key' => @api_key,
69
+ 'cx' => @cse_id
70
+ }
71
+ end
72
+
73
+ def service
74
+ client.discovered_api('customsearch')
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,5 @@
1
+ module Google
2
+ module Csene
3
+ VERSION = '0.3.1'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-csene
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Hirofumi Wakasugi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: google-api-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Easy to get some Google CSE results including search ranks and index
56
+ count.
57
+ email:
58
+ - komagata@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - google-csene.gemspec
73
+ - lib/google/csene.rb
74
+ - lib/google/csene/client.rb
75
+ - lib/google/csene/version.rb
76
+ homepage: https://github.com/5t111111/google-csene
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Easy to get some Google CSE results including search ranks and index count.
100
+ test_files: []
101
+ has_rdoc: