si-copyscape 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://www.copyscape.com/api/?c=3&e=UTF-8&k=test&o=psearch&u=test
6
+ body:
7
+ encoding: UTF-8
8
+ string: Because they are far less expensive when used, impractical vehicles
9
+ sell well in the secondary market.
10
+ headers:
11
+ Accept-Encoding:
12
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
13
+ Accept:
14
+ - "*/*"
15
+ User-Agent:
16
+ - Ruby
17
+ response:
18
+ status:
19
+ code: 200
20
+ message: OK
21
+ headers:
22
+ Date:
23
+ - Wed, 26 Aug 2015 17:03:50 GMT
24
+ Server:
25
+ - Apache/2.2.15 (CentOS)
26
+ X-Powered-By:
27
+ - PHP/5.3.3
28
+ Set-Cookie:
29
+ - ck=A4D7XKCZ0AO0KGWG80G88KCS4; expires=Fri, 25-Aug-2017 17:03:50 GMT; path=/;
30
+ domain=.copyscape.com
31
+ Content-Length:
32
+ - '1081'
33
+ Connection:
34
+ - close
35
+ Content-Type:
36
+ - text/xml; charset=utf-8
37
+ body:
38
+ encoding: UTF-8
39
+ string: "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<response>\n\t<querywords>17</querywords>\n\t<count>1</count>\n\t<result>\n\t\t<index>1</index>\n\t\t<url></url>\n\t\t<id>88029</id>\n\t\t<handle>SIA_2_E00JOQ0A2W_OJLHS6GHNQ</handle>\n\t\t<articlewords>553</articlewords>\n\t\t<added>2015-08-26
40
+ 17:06:42</added>\n\t\t<title>Content Manager Content Version for item: 22003</title>\n\t\t<textsnippet>
41
+ ... are far less expensive when used, impractical vehicles sell well in the
42
+ secondary market ... </textsnippet>\n\t\t<htmlsnippet> ... are far less expensive
43
+ when used, impractical vehicles sell well in the secondary market ... </htmlsnippet>\n\t\t<minwordsmatched>14</minwordsmatched>\n\t\t<wordsmatched>16</wordsmatched>\n\t\t<textmatched>Because
44
+ they are far less expensive when used, impractical vehicles sell well in the
45
+ secondary market</textmatched>\n\t\t<percentmatched>94</percentmatched>\n\t</result>\n\t<allwordsmatched>16</allwordsmatched>\n\t<allpercentmatched>94</allpercentmatched>\n\t<alltextmatched>Because
46
+ they are far less expensive when used, impractical vehicles sell well in the
47
+ secondary market</alltextmatched>\n</response>\n"
48
+ http_version:
49
+ recorded_at: Wed, 26 Aug 2015 17:08:02 GMT
50
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,89 @@
1
+ require 'test_helper'
2
+
3
+ class TestCopyscape < Minitest::Test
4
+ def setup
5
+ @cs = begin_copyscape
6
+
7
+ VCR.use_cassette("api_balance") do
8
+ @credit_balance = @cs.credit_balance
9
+ end
10
+ VCR.use_cassette("api_add_to_private_index") do
11
+ @private_index = @cs.add_to_private_index(text: 'Putting some text in our private index. Fee Fi Fo Fum I smell the blood of an englishman')
12
+ end
13
+ end
14
+
15
+ def test_error
16
+ VCR.use_cassette("api_error") do
17
+ response = @cs.internet_matches! 'test'
18
+ error = 'At least 15 words are required to perform a search'
19
+ assert_equal(response.error, error)
20
+ end
21
+
22
+ VCR.use_cassette("api_internet_matches") do
23
+ response = @cs.internet_matches! 'A national website promotion company, Search Influence routinely delivers a 10:1 return on investment, or better, for our customers.'
24
+ assert_nil(response.error, "When no errors, error should return nil")
25
+ end
26
+ end
27
+
28
+ def test_credit_balance
29
+ assert_instance_of(SI::CopyScape::Balance, @credit_balance)
30
+ end
31
+
32
+ def test_credit_balance_value
33
+ assert(@credit_balance.value.is_a?(Float), "Credit Balance value must be a Float")
34
+ assert_equal(@credit_balance.value, 240.51)
35
+ end
36
+
37
+ def test_credit_balance_total
38
+ assert(@credit_balance.total.is_a?(Integer), "Credit Total must be an Int")
39
+ assert_equal(@credit_balance.total, 4810)
40
+ end
41
+
42
+ def test_credit_balance_today
43
+ assert(@credit_balance.today.is_a?(Integer), "Credit Total Today must be an Int")
44
+ assert_equal(@credit_balance.today, 4810)
45
+ end
46
+
47
+ def test_internet_matches
48
+ VCR.use_cassette("api_internet_matches") do
49
+ response = @cs.internet_matches! 'A national website promotion company, Search Influence routinely delivers a 10:1 return on investment, or better, for our customers.'
50
+ assert_instance_of(SI::CopyscapeMatches, response)
51
+ end
52
+ end
53
+
54
+ def test_private_matches
55
+ VCR.use_cassette("api_private_matches") do
56
+ response = @cs.private_matches! 'Because they are far less expensive when used, impractical vehicles sell well in the secondary market.'
57
+ assert_instance_of(SI::CopyscapeMatches, response)
58
+ end
59
+ end
60
+
61
+ def test_internet_and_private_matches
62
+ VCR.use_cassette("api_internet_and_private_matches") do
63
+ response = @cs.internet_and_private_matches! 'A national website promotion company, Search Influence routinely delivers a 10:1 return on investment, or better, for our customers.'
64
+ assert_instance_of SI::CopyscapeMatches, response
65
+ end
66
+ end
67
+
68
+ def test_add_to_private_index
69
+ assert_instance_of SI::CopyScape::PrivateIndex, @private_index
70
+ end
71
+
72
+ def test_private_index_words
73
+ assert(@private_index.words.is_a?(Integer), 'Private Index words must return an integer')
74
+ assert_equal(@private_index.words, 18)
75
+ end
76
+
77
+ def test_private_index_handle
78
+ assert(@private_index.handle.is_a?(String), 'Private Index handle must return a string')
79
+ assert_equal(@private_index.handle, 'SIA_2_E00JOQ0A2W_F0N8GRC4GS')
80
+ end
81
+
82
+ def test_private_index_id
83
+ assert_nil(@private_index.id)
84
+ end
85
+
86
+ def test_private_index_title
87
+ assert_nil(@private_index.title)
88
+ end
89
+ end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ class TestCopyscapeAPI < Minitest::Test
4
+ def test_request
5
+ api = SI::CopyscapeAPI.new(
6
+ username: 'test',
7
+ api_key: 'test',
8
+ api_url: 'http://www.copyscape.com/api/'
9
+ )
10
+ VCR.use_cassette("api_balance") do
11
+ response = api.request(operation: 'balance')
12
+ assert_instance_of SI::CopyscapeResponse, response
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+
3
+ class TestCopyscapeMatches < Minitest::Test
4
+ def setup
5
+ VCR.use_cassette("api_internet_matches") do
6
+ cs = begin_copyscape
7
+ @matches = cs.internet_matches! 'A national website promotion company, Search Influence routinely delivers a 10:1 return on investment, or better, for our customers.'
8
+ @match = @matches.first
9
+ end
10
+ end
11
+
12
+ def test_matches_object
13
+ assert_instance_of(SI::CopyscapeMatches, @matches)
14
+ assert(@matches.is_a?(Enumerable), 'Expected matches to be enumerable')
15
+ end
16
+
17
+ def test_matches_object_count
18
+ assert_equal(@matches.count, 2, 'What goes in should come out')
19
+ end
20
+
21
+ def test_match_object
22
+ assert_instance_of(SI::CopyScape::Match, @match)
23
+ end
24
+
25
+ def test_match_html_snippet
26
+ snippet = '<font color="#777777">... Trusted, Scalable Search, Social and Online Advertising. </font><font color="#000000">A national website promotion company, Search Influence routinely delivers a 10:1 return on investment, or better, for our customers.</font>'
27
+ assert_equal(@match.html_snippet, snippet)
28
+ end
29
+
30
+ def test_match_test_snippet
31
+ snippet = '... Trusted, Scalable Search, Social and Online Advertising. A national website promotion company, Search Influence routinely delivers a 10:1 return on investment, or better, for our customers.'
32
+ assert_equal(@match.text_snippet, snippet)
33
+ end
34
+
35
+ def test_match_copyscape_url
36
+ url = 'http://view.copyscape.com/compare/6jq6k9utaz/1'
37
+ assert_equal(@match.copyscape_url, url)
38
+ end
39
+
40
+ def test_match_url
41
+ url = 'http://www.searchinfluence.com/'
42
+ assert_equal(@match.url, url)
43
+ end
44
+
45
+ def test_match_title
46
+ title = 'Search Influence | Website Promotion Company'
47
+ assert_equal(@match.title, title)
48
+ end
49
+
50
+ def test_match_percent_matched
51
+ assert_equal(@match.percent_matched, 100)
52
+ end
53
+
54
+ def test_match_words_matched
55
+ assert_equal(@match.words_matched, 20)
56
+ end
57
+
58
+ def test_all_text_snippets
59
+ snippet = '... Trusted, Scalable Search, Social and Online Advertising. A national website promotion company, Search Influence routinely delivers a 10:1 return on investment, or better, for our customers.'
60
+ snippets = @matches.all_text_snippets
61
+ assert_kind_of(Array, snippets)
62
+ assert_equal(snippets.first, snippet)
63
+ end
64
+
65
+ def test_all_html_snippets
66
+ snippet = '<font color="#777777">... Trusted, Scalable Search, Social and Online Advertising. </font><font color="#000000">A national website promotion company, Search Influence routinely delivers a 10:1 return on investment, or better, for our customers.</font>'
67
+ snippets = @matches.all_html_snippets
68
+ assert_kind_of(Array, snippets)
69
+ assert_equal(snippets.first, snippet)
70
+ end
71
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ class TestCopyscapeResponse < Minitest::Test
4
+ def setup
5
+ api = SI::CopyscapeAPI.new(
6
+ username: 'test',
7
+ api_key: 'test',
8
+ api_url: 'http://www.copyscape.com/api/'
9
+ )
10
+ VCR.use_cassette("api_internet_matches") do
11
+ text = 'A national website promotion company, Search Influence routinely delivers a 10:1 return on investment, or better, for our customers.'
12
+ @response = api.request(operation: 'csearch', params: {c:3, e: 'UTF-8'}, postdata: text)
13
+ end
14
+ end
15
+
16
+ def test_raw_xml
17
+ assert_kind_of(String, @response.raw_xml, 'raw_xml should return an xml string')
18
+ end
19
+
20
+ def test_raw_hash
21
+ assert(@response.raw_hash.is_a?(Hash), "raw_hash method must return a hash")
22
+ end
23
+
24
+ def test_remaining_on_normal_search
25
+ assert_nil(@response.remaining, 'remaining should be nil if this isnt a balance check')
26
+ end
27
+
28
+ def test_remaining_on_balance_check
29
+ VCR.use_cassette("api_balance") do
30
+ api = SI::CopyscapeAPI.new(username: 'test', api_key: 'test', api_url: 'http://www.copyscape.com/api/')
31
+ balance_response = api.request(operation: 'balance')
32
+ assert_instance_of(SI::CopyscapeResponse, balance_response)
33
+ end
34
+ end
35
+
36
+ def test_response
37
+ assert(@response.response.is_a?(Hash), "response method must return a hash")
38
+ end
39
+
40
+ def test_results
41
+ assert(@response.results.is_a?(Array), 'results method must return an array')
42
+ end
43
+
44
+ def test_query_words
45
+ assert_equal(@response.query_words, 20)
46
+ end
47
+ end
@@ -0,0 +1,16 @@
1
+ require 'minitest/autorun'
2
+ require 'copyscape_api'
3
+ require 'copyscape'
4
+ require 'copyscape_matches'
5
+ require 'copyscape_response'
6
+ require 'crack'
7
+ require 'vcr'
8
+
9
+ VCR.configure do |config|
10
+ config.cassette_library_dir = "test/cassettes"
11
+ config.hook_into :webmock # or :fakeweb
12
+ end
13
+
14
+ def begin_copyscape
15
+ SI::CopyScape.new(username: 'test', api_key: 'test')
16
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: si-copyscape
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shane Kretzmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: guard-minitest
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
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
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: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: crack
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Allow any ruby application to easily interact with copyscape premium
98
+ api
99
+ email:
100
+ - SKretzmann@searchinfluence.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - Guardfile
109
+ - README.md
110
+ - lib/copyscape.rb
111
+ - lib/copyscape_api.rb
112
+ - lib/copyscape_matches.rb
113
+ - lib/copyscape_response.rb
114
+ - lib/si-copyscape.rb
115
+ - lib/version.rb
116
+ - si-copyscape.gemspec
117
+ - test/cassettes/api_add_to_private_index.yml
118
+ - test/cassettes/api_balance.yml
119
+ - test/cassettes/api_error.yml
120
+ - test/cassettes/api_internet_and_private_matches.yml
121
+ - test/cassettes/api_internet_matches.yml
122
+ - test/cassettes/api_private_matches.yml
123
+ - test/test_copyscape.rb
124
+ - test/test_copyscape_api.rb
125
+ - test/test_copyscape_matches.rb
126
+ - test/test_copyscape_response.rb
127
+ - test/test_helper.rb
128
+ homepage: https://github.com/searchinfluence/copyscape
129
+ licenses:
130
+ - Private Property (c) Search Influence
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.2.2
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Gem to interface with Copyscape api
152
+ test_files:
153
+ - test/cassettes/api_add_to_private_index.yml
154
+ - test/cassettes/api_balance.yml
155
+ - test/cassettes/api_error.yml
156
+ - test/cassettes/api_internet_and_private_matches.yml
157
+ - test/cassettes/api_internet_matches.yml
158
+ - test/cassettes/api_private_matches.yml
159
+ - test/test_copyscape.rb
160
+ - test/test_copyscape_api.rb
161
+ - test/test_copyscape_matches.rb
162
+ - test/test_copyscape_response.rb
163
+ - test/test_helper.rb