to_net_me_api 0.4 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd730f66ada69ddbd416ca29cc66b19633006970
4
- data.tar.gz: 6b928259bf196e6461c86c5bc7c559f525c4f60e
3
+ metadata.gz: 2799f15b5571a8a6afb255ed1dbffb8e751daae1
4
+ data.tar.gz: 1acc8dc70cb7b48de9139c93ef3824512a464c43
5
5
  SHA512:
6
- metadata.gz: 8137e91e55ece85c4d08b497a0ff260b6242434c512f84a0269a468572618d874da1c1c56a333dcb0be30376fdf81d4dff33e766db8ae618c9168d5eadbcd243
7
- data.tar.gz: 227e5b435a7f9ea8bd59ae67ff30ea1800eb3a0587e3f094d4ab026a4f2acf16f04a28446dba622925a5ee18e2f3cd75da132de45fde567165b0382319056a6f
6
+ metadata.gz: 9f0caac5068a6137a294a4f5921b36d1b47b51240922f6a4a947f219c2bc59f8256214352ee18f9a0c902cda8c54d924b2df8e624d853266d2222d4ffc9d6bba
7
+ data.tar.gz: e82d83b88ab8d1c9b009e903c788812551787cbcee11924ee662c7fd3363073329b6d9b6f1a8741bbc060fe1c3c09f27e591339b3772473d4385735728ad8e4d
Binary file
File without changes
data/README.md CHANGED
@@ -63,6 +63,31 @@ groups.parsed_response #=> {"message"=>{"vk"=>[7389, {"gid"=>52734067, "name"=>"
63
63
  @to_net_me.search.groups_by_id(:gids=>['2net_me',37856556,38019449],:soc=>'vk')
64
64
  ```
65
65
 
66
+ ### Обработка капчи vkontakte
67
+ ``` ruby
68
+ # с помощью методов ToNetMeApi::Error.captcha_img и ToNetMeApi::Error.captcha_sid
69
+ # можно обработать ситуацию когда vk вернул нам 14 код
70
+ # пример
71
+
72
+ to_net_me = ToNetMeApi::Client.new(current_user.auth_key)
73
+ puts to_net_me.authorized?.inspect
74
+ begin
75
+ vk = to_net_me.test.captcha(:vk=>true)
76
+ puts vk.inspect
77
+ rescue ToNetMeApi::Error => e
78
+ if e.error_code == 14
79
+ # показываем юзеру картинку, URL которой
80
+ # можно получить методом e.captcha_img,
81
+ # и после этого снова вызываем метод:
82
+ vk = to_net_me.test.captcha(:vk=>true,:captcha_sid=>"тут должен быть sid",:captcha_key=>"тут должна быть капча с картинки")
83
+ puts vk.inspect
84
+ else
85
+ puts "Ошибка: " + e.error_code.to_s
86
+ end
87
+ ```
88
+
89
+
90
+
66
91
  ### Конфигурация
67
92
  ``` ruby
68
93
  # для смены адреса запроса api например на sandbox.api
Binary file
@@ -10,6 +10,8 @@ require 'to_net_me_api/resolvable'
10
10
  require 'to_net_me_api/client'
11
11
  require 'to_net_me_api/namespace'
12
12
  require 'to_net_me_api/method'
13
+ require 'to_net_me_api/error'
14
+ require 'to_net_me_api/result'
13
15
 
14
16
 
15
17
  # Main module.
@@ -19,7 +21,7 @@ module ToNetMeApi
19
21
  class << self
20
22
  # Creates a short alias `TNM` for `ToNetMeApi` module.
21
23
  def register_alias
22
- Object.const_set(:TNM, ToNetMeApi)
24
+ Object.const_set(:TNMG, ToNetMeApi)
23
25
  end
24
26
 
25
27
  # Removes the `TNM` alias.
@@ -27,4 +29,4 @@ module ToNetMeApi
27
29
  Object.send(:remove_const, :TNM) if defined?(TNM)
28
30
  end
29
31
  end
30
- end
32
+ end
@@ -5,11 +5,12 @@ module ToNetMeApi
5
5
  class << self
6
6
 
7
7
  def set_api_core
8
- unless ToNetMeApi.api_core
9
- ToNetMeApi.reset
10
- else
11
- ToNetMeApi.api_core
12
- end
8
+ "http://sandbox.api.2net.me/"
9
+ # unless ToNetMeApi.api_core
10
+ # ToNetMeApi.reset
11
+ # else
12
+ # ToNetMeApi.api_core
13
+ # end
13
14
  end
14
15
 
15
16
  def call(attrs,options={},auth_key = nil)
@@ -17,6 +18,8 @@ module ToNetMeApi
17
18
  options.merge!(@auth)
18
19
  HTTParty.get(set_api_core+attrs,:query => options)
19
20
  end
21
+
22
+
20
23
 
21
24
  end
22
25
  end
@@ -73,3 +73,57 @@ module ToNetMeApi
73
73
  end
74
74
  end
75
75
  end
76
+
77
+ # ToNetMeApi.configure {|config| config.api_core='http://sandbox.api.2net.me/'}
78
+ # to_net_me = ToNetMeApi::Client.new('01qw621sa14')
79
+ # puts to_net_me.authorized?.inspect
80
+ # begin
81
+ # vk = to_net_me.test.captcha(:gids=>'my_bikes',:vk=>1742410)
82
+ # puts vk.inspect
83
+ # rescue ToNetMeApi::Error => e
84
+ # if e.error_code == 14
85
+ # puts e.message
86
+ # puts e.error_code
87
+ # puts e.captcha_img
88
+ # vk = to_net_me.search.groupsbyid(:gids=>'my_bikes',:vk=>1742410,:captcha_sid=>"",:captcha_key=>"")
89
+ # # показываем юзеру картинку, URL которой
90
+ # # можно получить методом e.captcha_img,
91
+ # # и после этого снова вызываем метод:
92
+ # # puts vk.inspect
93
+ # # vk.wall.edit(post_id: 12345, message: 'hello world', captcha_sid: e.captcha_sid, captcha_key: params[:captcha])
94
+ # else
95
+ # puts "no 14"
96
+ # end
97
+ # end
98
+
99
+ # begin
100
+ # vk = to_net_me.search.groupsbyid(:gids=>'my_bikes',:vk=>1742410)
101
+ # puts vk.inspect
102
+ # rescue ToNetMeApi::Error => e
103
+ # if e.error_code == 14
104
+ # puts e.message
105
+ # puts e.error_code
106
+ # puts e.captcha_img
107
+ # vk = to_net_me.search.groupsbyid(:gids=>'my_bikes',:vk=>1742410,:captcha_sid=>"",:captcha_key=>"")
108
+ # # показываем юзеру картинку, URL которой
109
+ # # можно получить методом e.captcha_img,
110
+ # # и после этого снова вызываем метод:
111
+ # # puts vk.inspect
112
+ # # vk.wall.edit(post_id: 12345, message: 'hello world', captcha_sid: e.captcha_sid, captcha_key: params[:captcha])
113
+ # else
114
+ # puts "no 14"
115
+ # end
116
+ # end
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
File without changes
@@ -14,31 +14,31 @@ module ToNetMeApi
14
14
  # An exception is initialized by the data from response mash.
15
15
  # @param [Hash] data Error data.
16
16
  def initialize(data)
17
- @error_code = data.error_code
18
- @error_msg = data.error_msg
17
+ @error_code = data["error_code"]
18
+ @error_msg = data["error_msg"]
19
19
 
20
- request_params = parse_params(data.request_params)
20
+ request_params = parse_params(data["request_params"])
21
21
 
22
- @method_name = request_params.delete('method')
23
- @access_token = request_params.delete('access_token')
24
- @oauth = request_params.delete('oauth')
25
- @params = request_params
22
+ # @method_name = request_params.delete('method')
23
+ # @access_token = request_params.delete('access_token')
24
+ # @oauth = request_params.delete('oauth')
25
+ # @params = request_params
26
26
 
27
- @captcha_sid = data.captcha_sid
28
- @captcha_img = data.captcha_img
27
+ @captcha_sid = data["captcha_sid"]
28
+ @captcha_img = data["captcha_img"]
29
29
  end
30
30
 
31
31
  # A full description of the error.
32
32
  # @return [String]
33
33
  def message
34
34
  message = "VKontakte returned an error #{@error_code}: '#{@error_msg}'"
35
- message << " after calling method '#{@method_name}'"
35
+ # message << " after calling method '#{@method_name}'"
36
36
 
37
- if @params.empty?
38
- message << " without parameters."
39
- else
40
- message << " with parameters #{@params.inspect}."
41
- end
37
+ # if @params.empty?
38
+ # message << " without parameters."
39
+ # else
40
+ # message << " with parameters #{@params.inspect}."
41
+ # end
42
42
 
43
43
  message
44
44
  end
@@ -12,9 +12,8 @@ module ToNetMeApi
12
12
  def call(args = {}, &block)
13
13
  # raise full_name.inspect
14
14
  response = API.call(full_name, args, auth_key)
15
- # raise type.inspect
16
15
  # когда ответ бует стандартизирован тогда нужно будет делать вывод результата иобработку ошибок
17
- # Result.process(response, type, block)
16
+ Result.process(response, type, block)
18
17
  end
19
18
 
20
19
  private
File without changes
@@ -5,3 +5,4 @@
5
5
  - users
6
6
  - index
7
7
  - help
8
+ - test
@@ -1,5 +1,6 @@
1
1
  module ToNetMeApi
2
2
 
3
+
3
4
  module Resolvable
4
5
  attr_reader :name
5
6
 
@@ -1,3 +1,4 @@
1
+ require 'hashie'
1
2
  module ToNetMeApi
2
3
  # A mixin for classes that will resolve other classes' objects via `#method_missing`.
3
4
  module Resolver
@@ -11,7 +11,6 @@ module ToNetMeApi
11
11
  # @return [Array, Hashie::Mash] The processed result.
12
12
  # @raise [ToNetMeApi::Error] raised when VKontakte returns an error response.
13
13
  def process(response, type, block)
14
- raise response['error_code'].inspect
15
14
  result = extract_result(response)
16
15
 
17
16
  if result.respond_to?(:each)
@@ -28,10 +27,10 @@ module ToNetMeApi
28
27
 
29
28
  private
30
29
  def extract_result(response)
31
- if response.error?
32
- raise ToNetMeApi::Error.new(response.error)
30
+ if error?(response)
31
+ raise ToNetMeApi::Error.new(response["message"]["error"])
33
32
  else
34
- response.response
33
+ response
35
34
  end
36
35
  end
37
36
 
@@ -44,6 +43,10 @@ module ToNetMeApi
44
43
  parameter
45
44
  end
46
45
  end
46
+
47
+ def error?(response)
48
+ response["message"].include?("error")
49
+ end
47
50
  end
48
51
  end
49
52
  end
@@ -1,4 +1,4 @@
1
1
  module ToNetMeApi
2
2
  # Library version.
3
- VERSION = '0.4'
3
+ VERSION = '0.6'
4
4
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
18
  s.require_paths = ['lib']
19
19
 
20
- s.required_ruby_version = '>= 1.9.3'
20
+ s.required_ruby_version = '>= 2.0.0'
21
21
 
22
22
  s.add_runtime_dependency 'httparty', '~> 0.11'
23
23
  s.add_runtime_dependency 'hashie', '~> 2.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_net_me_api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Chechaev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-25 00:00:00.000000000 Z
11
+ date: 2013-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -46,10 +46,12 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
+ - .DS_Store
49
50
  - .gitignore
50
51
  - .travis.yml
51
52
  - CHANGELOG.md
52
53
  - README.md
54
+ - lib/.DS_Store
53
55
  - lib/to_net_me_api.rb
54
56
  - lib/to_net_me_api/api.rb
55
57
  - lib/to_net_me_api/client.rb
@@ -75,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
77
  requirements:
76
78
  - - '>='
77
79
  - !ruby/object:Gem::Version
78
- version: 1.9.3
80
+ version: 2.0.0
79
81
  required_rubygems_version: !ruby/object:Gem::Requirement
80
82
  requirements:
81
83
  - - '>='
@@ -83,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
85
  version: '0'
84
86
  requirements: []
85
87
  rubyforge_project:
86
- rubygems_version: 2.0.6
88
+ rubygems_version: 2.1.11
87
89
  signing_key:
88
90
  specification_version: 4
89
91
  summary: Ruby wrapper for api.2net.me