google-search_rank 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4b08bb265b0647ac44aa5d9300a65db147b47dd
4
- data.tar.gz: 10ada8bd53bdcb3c7a790676279dbc4cdfbf41e1
3
+ metadata.gz: 979b91a4dd13f3617cbd4d4cbf5871b08c7fc716
4
+ data.tar.gz: c9914adc001381e0e58af8b3e5c5aebcb4b76168
5
5
  SHA512:
6
- metadata.gz: 216cf87d4fcd75db299a306effff7bb71e862604cc42be34197ac5bb4e5556bff1e2387caa26b56d659739ab3c66db13d557c39c41619be6fffbb823950d725e
7
- data.tar.gz: 0898d4a08e235679aac7935809648f5d96bdbbce6bcd92ff234346ae0e330dc7953d46928573fb936a72b93107f5ea84e40bfc216eb39ede7a2e18c388ef4481
6
+ metadata.gz: cf571ce192b8025d9330285b4ca9671d2043988ae1f13fb118d5f0162b8c9126e373ae1360b5cd102559fcf1b014c988b0897ea9f5f543d75ce0247d91a89d41
7
+ data.tar.gz: d7ced24c85d9e68c85289655ad4c2146859824c53d11783a3aa7f799f97841fe2cec247690f5e8fcbb99d7649b22dbdfecdaebeb0883236c5e9814aa82b39ab2
data/README.md CHANGED
@@ -20,7 +20,10 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ ```ruby
24
+ client = Google::SearchRank.new(api_key: "xxxx", cse_id: "xxxx")
25
+ rank = client.find("KEYWORD", %r{http://example.com/.*})
26
+ ```
24
27
 
25
28
  ## Development
26
29
 
@@ -7,42 +7,32 @@ module Google
7
7
  AUDIENCE = "https://accounts.google.com/o/oauth2/token"
8
8
  SCOPE = "https://www.googleapis.com/auth/cse"
9
9
 
10
- def initialize(app_name, key_path, key_pass,
11
- client_id, client_secret,
12
- api_key, cse_id)
13
- @app_name = app_name
14
- @key_path = key_path
15
- @key_pass = key_pass
16
- @client_id = client_id
17
- @client_secret = client_secret
10
+ def initialize(application_name: "google-search_rank",
11
+ application_version: "1.0",
12
+ api_key:,
13
+ cse_id:)
14
+ @application_name = application_name
15
+ @application_version = application_version
18
16
  @api_key = api_key
19
17
  @cse_id = cse_id
20
18
  end
21
19
 
22
- def authorize!
23
- @client = Google::APIClient.new(
24
- application_name: @app_name
20
+ def client
21
+ Google::APIClient.new(
22
+ application_name: @application_name,
23
+ application_version: @application_version,
24
+ authorization: nil
25
25
  )
26
- key = Google::APIClient::KeyUtils.load_from_pkcs12(
27
- @key_path, @key_pass
28
- )
29
- @client.authorization = Signet::OAuth2::Client.new(
30
- :token_credential_uri => TOKEN_CREDENTIAL_URI,
31
- :audience => AUDIENCE,
32
- :scope => SCOPE,
33
- :issuer => @client_secret,
34
- :signing_key => key,
35
- )
36
- @client.authorization.fetch_access_token!
37
- @search = @client.discovered_api('customsearch')
38
26
  end
39
27
 
40
- def find(query, link, page = 1)
41
- authorize! if @search.nil?
28
+ def service
29
+ client.discovered_api('customsearch')
30
+ end
42
31
 
32
+ def find(query, link, page = 1)
43
33
  start = (page - 1) * 10 + 1
44
- result = @client.execute(
45
- @search.cse.list,
34
+ result = client.execute(
35
+ service.cse.list,
46
36
  'key' => @api_key,
47
37
  'cx' => @cse_id,
48
38
  'q' => query,
@@ -1,5 +1,5 @@
1
1
  module Google
2
2
  class SearchRank
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-search_rank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Komagata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-25 00:00:00.000000000 Z
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client
@@ -96,3 +96,4 @@ signing_key:
96
96
  specification_version: 4
97
97
  summary: Easy to get to Google Search ranks.
98
98
  test_files: []
99
+ has_rdoc: