ya_metrika 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 243369e0eb0e4ab691b7f0eb41045bd75e33ab39
4
+ data.tar.gz: c8120616b4e5d5269773a5338f02ae2f35138c8c
5
+ SHA512:
6
+ metadata.gz: c097d5fa89ad95a59c40041397f0b83a15bda3f17907104370d4d24733205dcc1c731fd288c066e7b613a14193ffe7a306b51adf63d35fbe0cc6459145329d7f
7
+ data.tar.gz: be179d9a93993f8984de857b1748113d6cd06e74ff7a528e54716a93a9492aa5116fa9a69a71fca2dda5abe392e33c10aec505dec9f1920b4efcb9e5ca3e7225
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ya_metrika.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ivan Bondarenko
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # YaMetrika
2
+
3
+ Ruby gem for [API Yandex Metrika](https://api.yandex.ru/metrika/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+ ```ruby
9
+ gem 'ya_metrika'
10
+ ```
11
+ And then execute:
12
+ ```console
13
+ $ bundle
14
+ ```
15
+ Or install it yourself as:
16
+ ```console
17
+ $ gem install ya_metrika
18
+ ```
19
+
20
+ ## Usage
21
+ ```ruby
22
+ require 'ya_metrika'
23
+
24
+ # Set config params or set its as a hash of options in constructor of YaMetrika::Client
25
+ # YaMetrika::Client.new(oauth_token: '05dd3dd84ff948fdae2bc4fb91f13e22')
26
+ # Default format is json
27
+ YaMetrika::Settings[:format] = :json # or :xml
28
+ YaMetrika::Settings[:oauth_token] = '05dd3dd84ff948fdae2bc4fb91f13e22'
29
+
30
+ client = YaMetrika::Client.new
31
+
32
+ response = client.counter(2215573).goal(334423).get
33
+
34
+ response = client.stat.traffic.summary.get(id: 2138128)
35
+
36
+ # OR
37
+ client.stat
38
+ client.traffic
39
+ client.summary
40
+ response = client.get(id: 2138128)
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/shved270189/ya_metrika )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ require 'ya_metrika/version'
2
+ require 'ya_metrika/client'
3
+
4
+ module YaMetrika
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,48 @@
1
+ require 'ya_metrika/settings'
2
+ require 'rest_client'
3
+
4
+ module YaMetrika
5
+ class Client
6
+ HOST = 'http://api-metrika.yandex.ru'
7
+ REST_METHODS = [:get, :post, :put, :delete]
8
+
9
+ def initialize(options = {})
10
+ options = YaMetrika::Settings.to_hash.merge(options)
11
+ @format = options[:format]
12
+ @oauth_token = options[:oauth_token]
13
+
14
+ @spells = Array.new
15
+ end
16
+
17
+ def method_missing(meth, *args, &block)
18
+ if YaMetrika::Client::REST_METHODS.include?(meth.to_sym)
19
+ rest(meth, *args, &block)
20
+ else
21
+ @spells << meth.to_s
22
+ @spells << args.first.to_s if args.first
23
+ self
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def request_path(options)
30
+ [@spells.inject('') {|r, spell| r + '/' + spell}, '.', @format.to_s, request_params(options)].join
31
+ end
32
+
33
+ def request_url(options)
34
+ YaMetrika::Client::HOST + request_path(options)
35
+ end
36
+
37
+ def request_params(options)
38
+ options.inject("?oauth_token=#{@oauth_token}") { |res, option| res + "&#{option.to_a.first.join('=')}" }
39
+ end
40
+
41
+ def rest(meth, *args, &block)
42
+ url = request_url(args)
43
+ @spells = Array.new
44
+
45
+ RestClient.send(meth.to_sym, url)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ module YaMetrika
2
+ class Settings
3
+ @config = {
4
+ format: :json,
5
+ oauth_token: nil
6
+ }
7
+
8
+ class << self
9
+ def [](key)
10
+ @config[key.to_sym]
11
+ end
12
+
13
+ def []=(key, value)
14
+ @config[key.to_sym] = value
15
+ end
16
+
17
+ def to_hash
18
+ @config
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module YaMetrika
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ya_metrika/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ya_metrika'
8
+ spec.version = YaMetrika::VERSION
9
+ spec.authors = ['Ivan Bondarenko']
10
+ spec.email = ['bondarenko.dev@gmail.com']
11
+ spec.summary = 'Ruby gem for API Yandex Metrika'
12
+ spec.homepage = 'https://github.com/shved270189/ya_metrika'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'rest-client', '~> 1.7'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.6'
23
+ spec.add_development_dependency 'rake', '~> 0'
24
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ya_metrika
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Bondarenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - bondarenko.dev@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/ya_metrika.rb
68
+ - lib/ya_metrika/client.rb
69
+ - lib/ya_metrika/settings.rb
70
+ - lib/ya_metrika/version.rb
71
+ - ya_metrika.gemspec
72
+ homepage: https://github.com/shved270189/ya_metrika
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Ruby gem for API Yandex Metrika
96
+ test_files: []