shared_count-cli 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +1 -0
- data/.gitignore +19 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +9 -0
- data/bin/shared_count-cli +9 -0
- data/config/initializers/dotenv.rb +3 -0
- data/config/initializers/shared_count_api.rb +0 -0
- data/lib/shared_count/cli.rb +48 -0
- data/lib/shared_count/cli/version.rb +5 -0
- data/shared_count-cli.gemspec +26 -0
- data/spec/shared_count/cli_spec.rb +21 -0
- data/spec/spec_helper.rb +2 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c3111abeaf8c7634190475c25146259569027a4
|
4
|
+
data.tar.gz: 52a4ad77c5fd35502554a1a3a872f9b4f07b0a0e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e91498ba39a144ba4478a6d8be707d01937b4d6d245105ddcceb7a49fa3457b880c7d009f7fe3045a962d85ff69cd8442631c7ad003ef4e6ab372550e4af19cb
|
7
|
+
data.tar.gz: 53d75baa64822207eda1fdbae2ba4dd78a49a0a5bfeb1600bd5e8095d032bdc65a98917f59cfdbe1c570f70466f1de462686ef50b763ad2180500ec537df9402
|
data/.env.example
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
SHARED_COUNT_APIKEY=secret
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Cristian Rasch
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# SharedCount::Cli
|
2
|
+
|
3
|
+
CLI to the shared_count_api gem
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install shared_count-cli
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
> Note: supports bash globbing
|
12
|
+
|
13
|
+
* Redirect the CSV file to stdout
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
$ ruby bin/shared_count-cli ~/Desktop/file?.txt # => ~/Desktop/file1.txt ~/Desktop/file2.txt
|
17
|
+
```
|
18
|
+
|
19
|
+
* Redirect the CSV file to a file
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
$ ruby bin/shared_count-cli ~/Desktop/file?.txt > ~/Desktop/output.csv
|
23
|
+
```
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( http://github.com/<my-github-username>/shared_count-cli/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "csv"
|
2
|
+
require "shared_count_api"
|
3
|
+
|
4
|
+
require_relative "../../config/initializers/dotenv"
|
5
|
+
require_relative "../../config/initializers/shared_count_api.rb"
|
6
|
+
|
7
|
+
require_relative "cli/version"
|
8
|
+
|
9
|
+
module SharedCount
|
10
|
+
module Cli
|
11
|
+
class << self
|
12
|
+
def run(lines)
|
13
|
+
configure_shared_count_client
|
14
|
+
|
15
|
+
CSV.generate do |csv|
|
16
|
+
lines.each_with_index do |url, i|
|
17
|
+
url.chomp!
|
18
|
+
response = nil
|
19
|
+
begin
|
20
|
+
response = SharedCountApi::Client.new(url).response
|
21
|
+
rescue SharedCountApi::Error
|
22
|
+
next
|
23
|
+
end
|
24
|
+
|
25
|
+
facebook_metrics = response.delete("Facebook")
|
26
|
+
if i.zero?
|
27
|
+
keys = response.keys.unshift("URL")
|
28
|
+
headers = keys.concat(facebook_metrics.keys)
|
29
|
+
csv << headers
|
30
|
+
csv << []
|
31
|
+
end
|
32
|
+
|
33
|
+
values = response.values.unshift(url)
|
34
|
+
csv << values.concat(facebook_metrics.values)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def configure_shared_count_client
|
42
|
+
SharedCountApi.configure do |config|
|
43
|
+
config.apikey = ENV["SHARED_COUNT_APIKEY"]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'shared_count/cli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "shared_count-cli"
|
8
|
+
spec.version = SharedCount::Cli::VERSION
|
9
|
+
spec.authors = ["Cristian Rasch"]
|
10
|
+
spec.email = ["cristianrasch@gmail.com"]
|
11
|
+
spec.summary = %q{CLI to the shared_count_api gem.}
|
12
|
+
spec.homepage = "https://github.com/wecodeio/shared_count-cli"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
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_runtime_dependency "shared_count_api", "~> 0.2"
|
21
|
+
spec.add_runtime_dependency "dotenv"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.2.0"
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
|
3
|
+
require_relative "../../lib/shared_count/cli"
|
4
|
+
|
5
|
+
describe SharedCount::Cli do
|
6
|
+
describe ".run" do
|
7
|
+
let(:urls) do
|
8
|
+
["http://slashdot.org\n", "http://bbc.co.uk\n", "http://www.lanacion.com.ar\n", "http://www.theguardian.com\n"]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "queries the SharedCount API for each URL passed in" do
|
12
|
+
csv = SharedCount::Cli.run(urls)
|
13
|
+
|
14
|
+
arr = CSV.parse(csv, headers: :first_row)
|
15
|
+
arr[1]["URL"].must_equal "http://slashdot.org"
|
16
|
+
arr[2]["URL"].must_equal "http://bbc.co.uk"
|
17
|
+
arr[3]["URL"].must_equal "http://www.lanacion.com.ar"
|
18
|
+
arr[4]["URL"].must_equal "http://www.theguardian.com"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shared_count-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cristian Rasch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: shared_count_api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dotenv
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 5.2.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 5.2.0
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- cristianrasch@gmail.com
|
86
|
+
executables:
|
87
|
+
- shared_count-cli
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".env.example"
|
92
|
+
- ".gitignore"
|
93
|
+
- ".ruby-version"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/shared_count-cli
|
99
|
+
- config/initializers/dotenv.rb
|
100
|
+
- config/initializers/shared_count_api.rb
|
101
|
+
- lib/shared_count/cli.rb
|
102
|
+
- lib/shared_count/cli/version.rb
|
103
|
+
- shared_count-cli.gemspec
|
104
|
+
- spec/shared_count/cli_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
homepage: https://github.com/wecodeio/shared_count-cli
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.2.0
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: CLI to the shared_count_api gem.
|
130
|
+
test_files:
|
131
|
+
- spec/shared_count/cli_spec.rb
|
132
|
+
- spec/spec_helper.rb
|