yandex-api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -27,17 +27,7 @@
27
27
  application_id: "id"
28
28
  login: "login"
29
29
  locale: "ru"
30
- debug: true
31
-
32
- Пример работы с gem-ом:
33
-
34
- require 'yandex-api'
35
- Yandex::API::Direct.load "yandex_direct.yml"
36
-
37
- campaign = Yandex::API::Direct::CampaignInfo.list.first
38
-
39
- puts campaign.inspect
40
- puts campaign.banners.first.inspect
30
+ verbose: true
41
31
 
42
32
  ## в Ruby On Rails:
43
33
 
@@ -48,8 +38,17 @@
48
38
  application_id: "id"
49
39
  login: "login"
50
40
  locale: "ru"
51
- debug: true
41
+ verbose: true
52
42
 
53
43
  Добавить в initializers файл yandex_direct.rb
54
44
 
55
45
  Yandex::API::Direct.load File.join(Rails.root,"config","yandex_direct.yml"), Rails.env
46
+
47
+ ## Пример работы:
48
+
49
+ require 'yandex-api'
50
+ Yandex::API::Direct.load "yandex_direct.yml"
51
+
52
+ campaign = Yandex::API::Direct::CampaignInfo.list.first
53
+ puts campaign.inspect
54
+ puts campaign.banners.first.inspect
@@ -16,26 +16,35 @@ module Yandex
16
16
  end
17
17
  @configuration
18
18
  end
19
+
20
+ def self.parse_json json
21
+ begin
22
+ return JSON.parse(json)
23
+ rescue => e
24
+ raise RuntimeError.new "#{e.message} in response"
25
+ end
26
+ end
19
27
 
20
28
  def self.load file, env = nil
21
29
  @enviroment = env if env
22
30
  config = YAML.load_file(file)
23
31
  @configuration = defined?(@enviroment) ? config[@enviroment] : config
24
32
  end
25
-
33
+
26
34
  def self.request method, params = {}
35
+
27
36
  body = {
28
37
  :locale => configuration["locale"],
29
38
  :login => configuration["login"],
30
39
  :application_id => configuration["application_id"],
31
- :token => configuration["token"],
40
+ :token => configuration["application_token"],
32
41
  :method => method
33
42
  }
34
43
 
35
44
  body.merge!({:param => params}) unless params.empty?
36
45
  url = URI.parse(URL_API)
37
46
 
38
- if configuration["debug"]
47
+ if configuration["verbose"]
39
48
  puts "\t\033[32mURL: \033[0m#{URL_API}"
40
49
  puts "\t\033[32mMethod: \033[0m#{method}"
41
50
  puts "\t\033[32mParams: \033[0m#{params.inspect}"
@@ -48,17 +57,11 @@ module Yandex
48
57
 
49
58
  raise Yandex::API::RuntimeError.new("#{response.code} - #{response.message}") unless response.code.to_i == 200
50
59
 
51
- json = {}
60
+ json = Direct.parse_json(response.body)
52
61
 
53
- begin
54
- json = JSON.parse(response.body)
55
- rescue => e
56
- raise RuntimeError.new "#{e.message} in response"
57
- end
58
-
59
- if json.has_key?("error_code")
62
+ if json.has_key?("error_code") and json.has_key?("error_str")
60
63
  code = json["error_code"].to_i
61
- error = json.has_key?("error_detail") ? json["error_detail"] : json["error_str"]
64
+ error = json["error_detail"].length > 0 ? json["error_detail"] : json["error_str"]
62
65
  raise RuntimeError.new "#{code} - #{error}"
63
66
  end
64
67
 
@@ -1,5 +1,5 @@
1
1
  module Yandex
2
2
  module API
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yandex-api
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-08-08 00:00:00.000000000 Z
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Yandex.API integration
15
15
  email: