watson-api-client 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -3
  3. data/lib/watson-api-client.rb +13 -7
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fec45c50b850da9cd802179d152e89d98891076
4
- data.tar.gz: 773b646ed640000c56789f6d07083274b1e40ded
3
+ metadata.gz: 2853333b50372507056bf65468d99248c3c8fc02
4
+ data.tar.gz: 37206172f43a2f9d38d5e121ea697d3fba10edda
5
5
  SHA512:
6
- metadata.gz: 28a9d5c4e20a7eb5bf088a1a075883165958dd4df037e5d3d1268fcc0eafbef9efa10b23e916ce50164262b0efe47272368b66112818a3936da788e1ba6b056d
7
- data.tar.gz: 8a17361402286dffe07a2c34724ba537c68fe37b1aeb528b0111b2164293d7a4c109b478039af3f072aebfe425a1546b2eb7bcc40890035eeb49550c55e57695
6
+ metadata.gz: d7111a654d49c0314c20ce32f541613a8db16bd6fd1ca4a51628cfe55ac247dece5903cf34bc95827de58b6afa82028581976ac9c8c4fe5aa8f3d5eba9b99800
7
+ data.tar.gz: 4d6dfe01b59a98402a86e65d98671f4135a08e69c58cae13275a492dc59381842731fa4e2a31dcc2055948a6ba13c1d10fd184f20212ca0fff26d1fec94fa115
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- watson-api-client - An IBM Watson™ API client
1
+ watson-api-client - An IBM Watson™ API client
2
2
  ================================================================
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/watson-api-client.svg)](http://badge.fury.io/rb/watson-api-client)
@@ -24,8 +24,14 @@ Documentation
24
24
  The simple API documentation for the watson-api-client is available on [RubyDoc.info](http://rubydoc.info/gems/watson-api-client).
25
25
 
26
26
  However, most of the classes and methods of this gem are not described in the above document because they are dynamically defined.
27
- Instead, you can output to the standard output the actual those list of classes and methods when you run the lib/watson-api-client.rb directly.
27
+ Instead, you can output to the standard output the actual those list of classes and methods when you run the lib/watson-api-client.rb directly, or
28
+ you can also use the following method to view a list of known APIs:
28
29
 
30
+ ```
31
+ require 'watson-api-client'
32
+
33
+ puts WatsonAPIClient::AvailableAPIs
34
+ ```
29
35
 
30
36
  Source Code
31
37
  -----------
@@ -102,7 +108,7 @@ Next, let's use 'Personality Insights'.
102
108
  The class name, the method name, and the argument setting rules are the same as that of the case of 'Relationship Extraction' almost.
103
109
  The rest-client and the watson-api-client judge which of path, query, header, body each argument is used for automatically.
104
110
 
105
- More
111
+ Additional note at the release of the version 0.0.3
106
112
  -------
107
113
  The documents which 'watson-api-client' referred to have changed in [February 2016](https://github.com/suchowan/watson-api-client/issues/1).
108
114
 
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'json'
2
2
  require 'openssl'
3
3
  require 'open-uri'
4
4
  require 'rest-client'
@@ -6,7 +6,7 @@ require 'pp' if __FILE__ == $PROGRAM_NAME
6
6
 
7
7
  class WatsonAPIClient
8
8
 
9
- VERSION = '0.0.3'
9
+ VERSION = '0.0.4'
10
10
 
11
11
  class << self
12
12
 
@@ -17,17 +17,17 @@ class WatsonAPIClient
17
17
 
18
18
  # Watson API Explorer
19
19
  host1 = doc_urls[:doc_base1][/^https?:\/\/[^\/]+/]
20
- open(doc_urls[:doc_base1], Options, &:read).scan(/<p>\s*<a href="\/(.+?)".*?>\s*(.+?)\s*<\/a><\/p>/i) do
20
+ open(doc_urls[:doc_base1], Options, &:read).scan(/<a class="swagger-list--item-link" href="\/(.+?)".*?>\s*(.+?)\s*<\/a>/i) do
21
21
  api = {'path'=>doc_urls[:doc_base1] + $1, 'title'=>$2.sub(/\s*\(.+?\)$/,'')}
22
22
  open(api['path'], Options, &:read).scan(/url:\s*'(.+?)'/) do
23
23
  api['path'] = host1 + $1
24
24
  end
25
25
  apis[api['title']] = api
26
26
  end
27
-
27
+
28
28
  # Watson Developercloud
29
29
  host2 = doc_urls[:doc_base2][/^https?:\/\/[^\/]+/]
30
- open(doc_urls[:doc_base2], Options, &:read).scan(/<li>\s*<img src=.+?>\s*<h2><a href="(.+?)".*?>\s*(.+?)\s*<\/a><\/h2>\s*<p>(.+?)<\/p>\s*<\/li>/im) do
30
+ open(doc_urls[:doc_base2], Options, &:read).scan(/<li>\s*<img.+data-src=.+?>\s*<h2><a href="(.+?)".*?>\s*(.+?)\s*<\/a><\/h2>\s*<p>(.+?)<\/p>\s*<\/li>/) do
31
31
  api = {'path'=>$1, 'title'=>$2, 'description'=>$3}
32
32
  next if api['path'] =~ /\.\./
33
33
  if apis.key?(api['title'])
@@ -59,7 +59,11 @@ class WatsonAPIClient
59
59
  body = parameter['name']
60
60
  break
61
61
  end
62
- nickname = operation['operationId'].sub(/(.)/) {$1.downcase}
62
+ if operation['operationId'].nil?
63
+ nickname = path
64
+ else
65
+ nickname = operation['operationId'].sub(/(.)/) {$1.downcase}
66
+ end
63
67
  methods[nickname] = {'method'=>method, 'path'=>path, 'operation'=>operation, 'body'=>body}
64
68
  digest[nickname] = {'method'=>method, 'path'=>path, 'summary'=>operation['summary']}
65
69
  end
@@ -71,7 +75,7 @@ class WatsonAPIClient
71
75
  api_docs = {
72
76
  :gateway => 'https://gateway.watsonplatform.net',
73
77
  :doc_base1 => 'https://watson-api-explorer.mybluemix.net/',
74
- :doc_base2 => 'https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/',
78
+ :doc_base2 => 'http://www.ibm.com/watson/developercloud/doc/',
75
79
  :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE
76
80
  }
77
81
  JSON.parse(ENV['WATSON_API_DOCS'] || '{}').each_pair do |key, value|
@@ -85,8 +89,10 @@ class WatsonAPIClient
85
89
  Gateway = api_docs.delete(:gateway)
86
90
  Options = api_docs
87
91
  Services = JSON.parse(ENV['VCAP_SERVICES'] || '{}')
92
+ AvailableAPIs = []
88
93
 
89
94
  retrieve_doc(doc_urls).each_value do |list|
95
+ AvailableAPIs << list['title'].gsub(/\s+(.)/) {$1.upcase}
90
96
  module_eval %Q{
91
97
  class #{list['title'].gsub(/\s+(.)/) {$1.upcase}} < self
92
98
  Service = superclass::Services['#{list['title'].sub(/\s+/,'_').downcase}']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watson-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi SUGA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-23 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client