impas-client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ *.swp
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
data/README.md CHANGED
@@ -1,20 +1,6 @@
1
1
  # Impas::Client
2
2
 
3
- TODO: Write a gem description
4
-
5
- ## Synopsys
6
-
7
- ```ruby
8
- require 'impas-client'
9
- client = Impas::Client.new({
10
- api_url:"http://local.impas-hideack.sqale.jp/",
11
- op_key:"4109b1be1e6a08b9f0b7ef2fa84c3e20"
12
- })
13
-
14
- client.add_group "foobar" # 集計グループ追加
15
- client.groups # 登録中のグループ一覧取得
16
-
17
- ```
3
+ Impas::Client is a Ruby interface for Impas API.
18
4
 
19
5
  ## Installation
20
6
 
@@ -32,7 +18,23 @@ Or install it yourself as:
32
18
 
33
19
  ## Usage
34
20
 
35
- TODO: Write usage instructions here
21
+ ```ruby
22
+ require 'impas-client'
23
+
24
+ client = Impas::Client.new({
25
+ api_url:"http://impas.****.jp/",
26
+ op_key:"*****"
27
+ })
28
+
29
+ client.add_group "sample_group1" # 集計グループ追加
30
+ client.groups # 登録中のグループ一覧取得
31
+
32
+ client.add_url( # URLを集計対象へ追加
33
+ "051fc80bff3afd1db52bfc3dae8f6329",
34
+ "http://www.youtube.com/watch?v=2HQkugdXyHY"
35
+ )
36
+
37
+ ```
36
38
 
37
39
  ## Contributing
38
40
 
data/impas-client.gemspec CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/impas-client/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["hideack"]
6
6
  gem.email = ["hide.terai@gmail.com"]
7
- gem.description = "impas client"
8
- gem.summary = "impas client"
7
+ gem.description = "Impas API client (Impas is social parameters crawling application.)"
8
+ gem.summary = "Impas API client"
9
9
  gem.homepage = "http://github.com/hideack/impas-client"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
data/lib/impas-client.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "impas-client/version"
2
2
  require 'faraday'
3
+ require 'json'
3
4
 
4
5
  module Impas
5
6
  class Client
@@ -10,36 +11,66 @@ module Impas
10
11
  @op_key = args[:op_key]
11
12
 
12
13
  @@conn = Faraday.new(:url => @api_url) do |faraday|
13
- faraday.request :url_encoded # form-encode POST params
14
- faraday.response :logger # log requests to STDOUT
15
- faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
14
+ faraday.request :url_encoded
15
+ faraday.adapter Faraday.default_adapter
16
16
  end
17
+
17
18
  end
18
19
 
19
20
  def add_group(group_name)
20
21
  entry_point = "/api/group/#{@op_key}"
21
22
 
22
- @@conn.post do |req|
23
+ res = @@conn.post do |req|
23
24
  req.url entry_point
24
25
  req.headers['Content-Type'] = 'application/json'
25
26
  req.body = "{\"name\":\"#{group_name}\"}"
26
27
  end
28
+
29
+ if res.status == 200
30
+ desc = JSON.parse(res.body)
31
+
32
+ if desc["result"] != "ok"
33
+ raise StandardError.new("Process error. message:#{desc['explain']}")
34
+ end
35
+ else
36
+ raise StandardError.new("HTTP status:#{res.status}")
37
+ end
38
+
39
+ true
27
40
  end
28
41
 
29
42
  def groups
30
43
  entry_point = "/api/group/#{@op_key}"
31
- @@conn.get entry_point
44
+ res = @@conn.get entry_point
45
+
46
+ if res.status != 200
47
+ raise StandardError.new("HTTP status:#{res.status}")
48
+ end
49
+
50
+ desc = JSON.parse(res.body)
51
+ desc["description"]["groups"]
32
52
  end
33
53
 
34
54
  def add_url(grp_key, url)
35
55
  entry_point = "/api/registration/#{grp_key}"
36
56
 
37
- @@conn.post do |req|
57
+ res = @@conn.post do |req|
38
58
  req.url entry_point
39
59
  req.headers['Content-Type'] = 'application/json'
40
60
  req.body = "{\"url\":\"#{url}\"}"
41
61
  end
42
- end
43
62
 
63
+ if res.status == 200
64
+ desc = JSON.parse(res.body)
65
+
66
+ if desc["result"] != "ok"
67
+ raise StandardError.new("Process error. message:#{desc['explain']}")
68
+ end
69
+ else
70
+ raise StandardError.new("HTTP status:#{res.status}")
71
+ end
72
+
73
+ true
74
+ end
44
75
  end
45
76
  end
@@ -1,6 +1,6 @@
1
1
  module Impas
2
2
  class Client
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  API_URL = "http://impas-hideack.sqale.jp/"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: impas-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
12
+ date: 2013-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -27,7 +27,7 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.8.4
30
- description: impas client
30
+ description: Impas API client (Impas is social parameters crawling application.)
31
31
  email:
32
32
  - hide.terai@gmail.com
33
33
  executables: []
@@ -65,5 +65,5 @@ rubyforge_project:
65
65
  rubygems_version: 1.8.19
66
66
  signing_key:
67
67
  specification_version: 3
68
- summary: impas client
68
+ summary: Impas API client
69
69
  test_files: []