highwinds-api 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -14
- data/.rspec +3 -0
- data/Gemfile +2 -5
- data/Gemfile.lock +32 -0
- data/highwinds-api.gemspec +2 -1
- data/lib/highwinds-api/content.rb +29 -19
- data/lib/highwinds-api/version.rb +1 -1
- data/lib/highwinds-api.rb +20 -3
- data/spec/config.example.yml +2 -0
- data/spec/content_spec.rb +83 -35
- data/spec/highwinds-api_spec.rb +30 -0
- metadata +29 -15
- data/spec/general_spec.rb +0 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 691f0f9c8235c31faa1205e5cea7b53be3636401
|
4
|
+
data.tar.gz: fba8b69d606d486442ba825340718acfab4307e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89c125373d2a361cc8fb439d547c857ca035df4d4587fbd0f53a4e80c57d7e80f25b8a1f2db66e64b6eea491fc361a5b08b895d46a5858c8f4bb4a38d88f68ea
|
7
|
+
data.tar.gz: ca30802de4882d4230de5924899fc9c9c9e553e104cd4aca4b3f3c1969dd4d7f8b636b9e709606a4d4f2b5fa0201816f8355dabf0ef08814aa4fe6a060ba95a5
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
highwinds-api (0.0.7)
|
5
|
+
httparty (~> 0.10)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
httparty (0.13.3)
|
12
|
+
json (~> 1.8)
|
13
|
+
multi_xml (>= 0.5.2)
|
14
|
+
json (1.8.2)
|
15
|
+
multi_xml (0.5.5)
|
16
|
+
rake (0.9.6)
|
17
|
+
rspec (2.11.0)
|
18
|
+
rspec-core (~> 2.11.0)
|
19
|
+
rspec-expectations (~> 2.11.0)
|
20
|
+
rspec-mocks (~> 2.11.0)
|
21
|
+
rspec-core (2.11.1)
|
22
|
+
rspec-expectations (2.11.3)
|
23
|
+
diff-lcs (~> 1.1.3)
|
24
|
+
rspec-mocks (2.11.3)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
highwinds-api!
|
31
|
+
rake (~> 0.9)
|
32
|
+
rspec (~> 2.11)
|
data/highwinds-api.gemspec
CHANGED
@@ -16,5 +16,6 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
-
gem.add_dependency "httparty", "~> 0.
|
19
|
+
gem.add_dependency "httparty", "~> 0.13"
|
20
|
+
gem.add_development_dependency "rspec", "~> 2.11"
|
20
21
|
end
|
@@ -2,33 +2,43 @@ module HighwindsAPI
|
|
2
2
|
require 'httparty'
|
3
3
|
class Content
|
4
4
|
include HTTParty
|
5
|
-
# debug_output $stdout # adds HTTP debugging
|
5
|
+
# debug_output $stdout # adds HTTP debugging
|
6
6
|
|
7
|
-
base_uri 'https://
|
7
|
+
base_uri 'https://striketracker3.highwinds.com/'
|
8
8
|
|
9
9
|
def self.purge_url(url, recursive)
|
10
10
|
options = {
|
11
|
-
:headers => { '
|
12
|
-
|
13
|
-
:
|
14
|
-
self.
|
11
|
+
:headers => { 'Authorization' => HighwindsAPI.get_token,
|
12
|
+
'Content-Type' => 'application/json'},
|
13
|
+
:body => {"list" => [{url: url, recursive: recursive }]}.to_json }
|
14
|
+
self.post("/api/v1/accounts/#{get_account_hash}/purge", options)
|
15
15
|
end
|
16
16
|
|
17
|
+
# This method returns the last item post result
|
17
18
|
def self.purge_path(host_hash, path)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
19
|
+
paths =[*path]
|
20
|
+
paths = paths.map {|single_path| single_path.start_with?('/') ? single_path : '/' << single_path }
|
21
|
+
res=nil
|
22
|
+
paths.each do |path|
|
23
|
+
options = {
|
24
|
+
:headers => { 'Authorization' => HighwindsAPI.get_token,
|
25
|
+
'Content-Type' => 'application/json'},
|
26
|
+
:body => {"list" => [{url: "http://cds.#{host_hash}.hwcdn.net#{path}", recursive: true }]}.to_json }
|
27
|
+
res = self.post("/api/v1/accounts/#{get_account_hash}/purge", options)
|
28
|
+
end
|
30
29
|
res
|
31
30
|
end
|
32
|
-
|
31
|
+
private
|
32
|
+
def self.get_token
|
33
|
+
response = self.post("/auth/token", {body: {grant_type: 'password', username: "#{HighwindsAPI.credentials[:username]}", password: "#{HighwindsAPI.credentials[:password]}"}})
|
34
|
+
"Bearer #{response['access_token']}"
|
35
|
+
end
|
36
|
+
def self.get_account_hash
|
37
|
+
options = {
|
38
|
+
:headers => { 'Authorization' => HighwindsAPI.get_token }
|
39
|
+
}
|
40
|
+
me = self.get('/api/v1/users/me', options)
|
41
|
+
me['accountHash'] if me.include?('accountHash')
|
42
|
+
end
|
33
43
|
end
|
34
44
|
end
|
data/lib/highwinds-api.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require "highwinds-api/version"
|
2
2
|
|
3
3
|
module HighwindsAPI
|
4
|
-
|
4
|
+
autoload :Content, "highwinds-api/content"
|
5
|
+
ONE_HOUR_IN_SECONDS = 3600
|
5
6
|
def self.credentials
|
6
|
-
{
|
7
|
-
:
|
7
|
+
{
|
8
|
+
username: @username,
|
9
|
+
password: @password
|
10
|
+
}
|
8
11
|
end
|
9
12
|
|
10
13
|
def self.set_credentials(username, password)
|
@@ -12,4 +15,18 @@ module HighwindsAPI
|
|
12
15
|
@password = password
|
13
16
|
end
|
14
17
|
|
18
|
+
def self.get_token
|
19
|
+
unless (@token_time and Time.now - @token_time < ONE_HOUR_IN_SECONDS)
|
20
|
+
@token = Content::get_token
|
21
|
+
@token_time = Time.now
|
22
|
+
end
|
23
|
+
@token
|
24
|
+
end
|
25
|
+
|
26
|
+
# should be used only in testing scenarios
|
27
|
+
def self.clear_token
|
28
|
+
@token = nil
|
29
|
+
@token_time = nil
|
30
|
+
end
|
31
|
+
|
15
32
|
end
|
data/spec/content_spec.rb
CHANGED
@@ -1,45 +1,93 @@
|
|
1
|
-
require '
|
2
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'highwinds-api'))
|
3
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'highwinds-api/content'))
|
4
|
-
|
5
|
-
describe 'HighwindsAPI::Content' do
|
6
|
-
username = "<YourUserHere>"
|
7
|
-
password = "<YourPasswordHere>"
|
8
|
-
it "should not purge content, if username and password are not correct." do
|
9
|
-
HighwindsAPI.set_credentials("bad username", "bad password")
|
10
|
-
r = HighwindsAPI::Content.purge_url("http://staging.crossrider.com/kerker/", true).response
|
11
|
-
r.code.should eq("403"), "response was: #{r}"
|
12
|
-
end
|
1
|
+
require 'highwinds-api'
|
13
2
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
3
|
+
describe HighwindsAPI::Content do
|
4
|
+
let(:config) { YAML.load_file('spec/config.yml') }
|
5
|
+
let(:client) { HighwindsAPI }
|
6
|
+
let(:content) { client::Content }
|
19
7
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
8
|
+
context "when credentials are incorrect" do
|
9
|
+
before do
|
10
|
+
client.clear_token
|
11
|
+
client.set_credentials("bad-username", "bad-password")
|
12
|
+
end
|
25
13
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
14
|
+
it "does not purge content" do
|
15
|
+
response = content.purge_url("http://staging.crossrider.com/kerker/", true).response
|
16
|
+
expect(response.code).to eq("401")
|
17
|
+
end
|
30
18
|
end
|
31
19
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
20
|
+
context "when credentials are correct" do
|
21
|
+
before do
|
22
|
+
client.clear_token
|
23
|
+
client.set_credentials(config["username"], config["password"])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should purge content by url" do
|
27
|
+
response = content.purge_url("http://staging.crossrider.com/kerker/", true)
|
28
|
+
response.include?("id").should eq(true), "response was: #{response}"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should purge folder by path" do
|
32
|
+
response = content.purge_path("y2s9x4y9", "/kerker/").response
|
33
|
+
response.code.should eq("200"), "response was: #{response} and response code was #{response.code} and response text #{response.body}"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should purge file by path" do
|
37
|
+
response = content.purge_path("y2s9x4y9", "kerker/akamai").response
|
38
|
+
response.code.should eq("200"), "response was: #{response}"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should purge folders by array of pathes" do
|
42
|
+
arr = ["kerker/akamai.txt", "kerker/akamai.htm", "kerker/akamai.gif"]
|
43
|
+
response = content.purge_path("y2s9x4y9", arr).response
|
44
|
+
response.code.should eq("200"), "response was: #{response}"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should ignore pathes ending with * (purge by path is allways recuresive)" do
|
48
|
+
response = content.purge_path("y2s9x4y9", "kerker/*").response
|
49
|
+
response.code.should eq("200"), "response was: #{response}"
|
50
|
+
end
|
37
51
|
end
|
38
52
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
53
|
+
describe "basic functionaility" do
|
54
|
+
let(:host_hash) { "xxxxxxxx" }
|
55
|
+
let(:path) { "baz/*" }
|
56
|
+
let(:url) { "http://foo.bar.com/baz" }
|
57
|
+
let(:recursive) { false }
|
58
|
+
let(:account_hash) {"d3b5s7n9"}
|
59
|
+
|
60
|
+
describe ".purge_url" do
|
61
|
+
it "calls post with given params" do
|
62
|
+
HighwindsAPI.clear_token
|
63
|
+
HighwindsAPI.set_credentials(config["username"], config["password"])
|
64
|
+
options = {
|
65
|
+
:headers => { 'Authorization' => HighwindsAPI.get_token,
|
66
|
+
'Content-Type' => 'application/json'},
|
67
|
+
:body => {"list" => [{url: url, recursive: recursive }]}.to_json }
|
68
|
+
|
69
|
+
content.should_receive(:post).\
|
70
|
+
with("/api/v1/accounts/#{account_hash}/purge", options).\
|
71
|
+
and_return("403")
|
72
|
+
content.purge_url(url, recursive)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
describe ".purge_path" do
|
78
|
+
it "calls post with given params" do
|
79
|
+
HighwindsAPI.clear_token
|
80
|
+
HighwindsAPI.set_credentials(config["username"], config["password"])
|
81
|
+
options = {
|
82
|
+
:headers => { 'Authorization' => HighwindsAPI.get_token,
|
83
|
+
'Content-Type' => 'application/json'},
|
84
|
+
:body => {"list" => [{url: "http://cds.xxxxxxxx.hwcdn.net/baz/*", recursive: true }]}.to_json }
|
85
|
+
content.should_receive(:post).\
|
86
|
+
with("/api/v1/accounts/#{account_hash}/purge", options).\
|
87
|
+
and_return("403")
|
88
|
+
content.purge_path(host_hash, path)
|
89
|
+
end
|
90
|
+
end
|
43
91
|
end
|
44
92
|
|
45
93
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'highwinds-api'
|
2
|
+
|
3
|
+
describe HighwindsAPI do
|
4
|
+
let(:config) { YAML.load_file('spec/config.yml') }
|
5
|
+
|
6
|
+
it "set credentials" do
|
7
|
+
username = "user"
|
8
|
+
password = "pass"
|
9
|
+
subject.set_credentials(username, password)
|
10
|
+
subject.credentials.should eq({ username: username, password: password })
|
11
|
+
end
|
12
|
+
|
13
|
+
it "get token" do
|
14
|
+
subject.set_credentials(config["username"], config["password"])
|
15
|
+
expect(subject.get_token.length).to be >= 20
|
16
|
+
end
|
17
|
+
|
18
|
+
it "get token snd time to be the same as first one" do
|
19
|
+
subject.set_credentials(config["username"], config["password"])
|
20
|
+
old_token = subject.get_token
|
21
|
+
new_token = subject.get_token
|
22
|
+
expect(new_token).to be(old_token)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
it "autoloads ::Content" do
|
27
|
+
# subject.autoload?(:Content).should eq("highwinds-api/content")
|
28
|
+
subject::Content.should eq(HighwindsAPI::Content)
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,32 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: highwinds-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ofir Kerker
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: httparty
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
19
|
+
version: '0.13'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
26
|
+
version: '0.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.11'
|
30
41
|
description: Ruby implementation of Highwinds REST API
|
31
42
|
email:
|
32
43
|
- ofir@crossrider.com
|
@@ -35,7 +46,9 @@ extensions: []
|
|
35
46
|
extra_rdoc_files: []
|
36
47
|
files:
|
37
48
|
- .gitignore
|
49
|
+
- .rspec
|
38
50
|
- Gemfile
|
51
|
+
- Gemfile.lock
|
39
52
|
- LICENSE.txt
|
40
53
|
- README.md
|
41
54
|
- Rakefile
|
@@ -43,32 +56,33 @@ files:
|
|
43
56
|
- lib/highwinds-api.rb
|
44
57
|
- lib/highwinds-api/content.rb
|
45
58
|
- lib/highwinds-api/version.rb
|
59
|
+
- spec/config.example.yml
|
46
60
|
- spec/content_spec.rb
|
47
|
-
- spec/
|
61
|
+
- spec/highwinds-api_spec.rb
|
48
62
|
homepage: https://github.com/kerkero/highwinds-api
|
49
63
|
licenses: []
|
64
|
+
metadata: {}
|
50
65
|
post_install_message:
|
51
66
|
rdoc_options: []
|
52
67
|
require_paths:
|
53
68
|
- lib
|
54
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
70
|
requirements:
|
57
|
-
- -
|
71
|
+
- - '>='
|
58
72
|
- !ruby/object:Gem::Version
|
59
73
|
version: '0'
|
60
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
75
|
requirements:
|
63
|
-
- -
|
76
|
+
- - '>='
|
64
77
|
- !ruby/object:Gem::Version
|
65
78
|
version: '0'
|
66
79
|
requirements: []
|
67
80
|
rubyforge_project:
|
68
|
-
rubygems_version:
|
81
|
+
rubygems_version: 2.0.14
|
69
82
|
signing_key:
|
70
|
-
specification_version:
|
83
|
+
specification_version: 4
|
71
84
|
summary: Ruby implementation of Highwinds REST API
|
72
85
|
test_files:
|
86
|
+
- spec/config.example.yml
|
73
87
|
- spec/content_spec.rb
|
74
|
-
- spec/
|
88
|
+
- spec/highwinds-api_spec.rb
|
data/spec/general_spec.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'highwinds-api'))
|
3
|
-
|
4
|
-
describe 'HighwindsAPI' do
|
5
|
-
username = "user"
|
6
|
-
password = "pass"
|
7
|
-
it "set credentials" do
|
8
|
-
HighwindsAPI.set_credentials(username, password)
|
9
|
-
HighwindsAPI.credentials.should eq({:username => username, :password => password})
|
10
|
-
end
|
11
|
-
end
|