foy_api_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6d02e68623fc8bdfb1f3b6219af0c1ebe2acd642
4
+ data.tar.gz: a88bf0a939e27e8f394395cc155383895b4a386e
5
+ SHA512:
6
+ metadata.gz: 36973db7718d54a40b6f639ef1db1aa5908e3d1c4a85611c0aeb9144a6480a204d9bd67f5094b71a96fb92148c4af2cb06bfbc9ee57455bbfa4844d435cdbd6c
7
+ data.tar.gz: 8a584fe17a89b269f984e56e28cc15896407c8f737b482e50fbc8ef948c772ae24fdcbd8970ab8c8e9e80c06bb24a240b2c0abdd46cd64a7132bb3131f397039
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .bundle
2
+ Gemfile.lock
3
+ pkg/
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ foy-api-client
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p353
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in foy-ruby-handler.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Roberto Soares, http://robertosoares.me/
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
File without changes
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'foy_api_client'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "foy_api_client"
7
+ gem.version = Foy::API::Client::VERSION
8
+ gem.authors = ["Roberto Soares"]
9
+ gem.email = ["contact@robertosoares.me"]
10
+ gem.summary = %q{FoY API Client}
11
+ gem.description = %q{FoY API Client}
12
+ gem.homepage = ""
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_development_dependency('rspec', '>= 2.14.1')
20
+ gem.add_development_dependency('webmock', '>= 1.17.1')
21
+
22
+ gem.add_dependency('rest-client', '>= 1.6.7')
23
+ end
@@ -0,0 +1,42 @@
1
+ require 'foy_api_client/version'
2
+ require 'rest-client'
3
+
4
+ module Foy
5
+ module API
6
+ module Client
7
+ class Base
8
+ def initialize(base_url)
9
+ @base_url = base_url
10
+ end
11
+
12
+ def get_projects
13
+ json_data = RestClient.get "#{@base_url}/v1/projects.json", {:accept => :json}
14
+ parse_collection(json_data)
15
+ end
16
+
17
+ def put_project_packages(project_id: nil, packages: [], system: nil)
18
+ RestClient.put "#{@base_url}/v1/projects/#{project_id}/packages.json", {packages: packages}.to_json, {params: {system: system}, accept: :json, content_type: :json}
19
+ end
20
+
21
+ def get_packages(system: system)
22
+ json_data = RestClient.get "#{@base_url}/v1/packages/#{system}.json", {:accept => :json}
23
+ parse_collection(json_data)
24
+ end
25
+
26
+ def put_packages(system: system, packages: [])
27
+ RestClient.put "#{@base_url}/v1/packages/#{system}.json", {packages: packages}.to_json, {accept: :json, content_type: :json}
28
+ end
29
+
30
+ private
31
+
32
+ def parse_collection(json_data)
33
+ data = JSON.parse(json_data)
34
+
35
+ data.collect do |element|
36
+ OpenStruct.new(element)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ module Foy
2
+ module API
3
+ module Client
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foy::API::Client::Base do
4
+ describe ".get_packages" do
5
+ subject do
6
+ Foy::API::Client::Base.new 'base'
7
+ end
8
+
9
+ let(:data) do
10
+ {
11
+ name: "rspec",
12
+ version: "1.0.2"
13
+ }
14
+ end
15
+
16
+ let(:data_json) do
17
+ [data].to_json
18
+ end
19
+
20
+ let(:system) do
21
+ 'pip'
22
+ end
23
+
24
+ before do
25
+ stub_request(:get, "base/v1/packages/#{system}.json").
26
+ to_return(status: 200, body: data_json)
27
+ end
28
+
29
+ it "calls /v1/projects.json" do
30
+ subject.get_packages(system: system)
31
+ WebMock.should have_requested(:get, "base/v1/packages/#{system}.json")
32
+ end
33
+
34
+ it "returns an array" do
35
+ result = subject.get_packages(system: system)
36
+ expect(result).to be_an(Array)
37
+ end
38
+
39
+ it "returns data as OpenStruct" do
40
+ result = subject.get_packages(system: system)
41
+ expect(result.first).to be == OpenStruct.new(data)
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foy::API::Client::Base do
4
+ describe "#get_projects" do
5
+ subject do
6
+ Foy::API::Client::Base.new 'base'
7
+ end
8
+
9
+ let(:data) do
10
+ {
11
+ id: "2",
12
+ repository: "New Repo",
13
+ title: "New Project"
14
+ }
15
+ end
16
+
17
+ let(:data_json) do
18
+ [data].to_json
19
+ end
20
+
21
+ before do
22
+ stub_request(:get, "base/v1/projects.json").
23
+ to_return(status: 200, body: data_json)
24
+ end
25
+
26
+ it "calls /v1/projects.json" do
27
+ subject.get_projects
28
+ WebMock.should have_requested(:get, "base/v1/projects.json")
29
+ end
30
+
31
+ it "returns an array" do
32
+ result = subject.get_projects
33
+ expect(result).to be_an(Array)
34
+ end
35
+
36
+ it "returns data as OpenStruct" do
37
+ result = subject.get_projects
38
+ expect(result.first).to be == OpenStruct.new(data)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foy::API::Client::Base do
4
+ describe "#put_project_packages" do
5
+ subject do
6
+ Foy::API::Client::Base.new 'base'
7
+ end
8
+
9
+ let(:system) do
10
+ "pip"
11
+ end
12
+
13
+ let(:data) do
14
+ [
15
+ {name: 'rest-client', version: '3.0.1'},
16
+ {name: 'rspec', version: '2.0.0'}
17
+ ]
18
+ end
19
+
20
+ let(:data_json) do
21
+ data.to_json
22
+ end
23
+
24
+ before do
25
+ stub_request(:put, /.*/).
26
+ to_return(status: 200)
27
+ end
28
+
29
+ it "calls put /v1/packages/pip.json" do
30
+ subject.put_packages(packages: data, system: 'pip')
31
+ WebMock.should have_requested(:put, "base/v1/packages/pip.json")
32
+ end
33
+
34
+ it "sends data as json" do
35
+ subject.put_packages(packages: data, system: 'rubygems')
36
+ WebMock.should have_requested(:put, /.*/).
37
+ with(body: {packages: data}.to_json)
38
+ end
39
+
40
+ it "indicates content as json" do
41
+ subject.put_packages(packages: data, system: 'rubygems')
42
+ WebMock.should have_requested(:put, /.*/).
43
+ with(headers: {"Content-Type" => 'application/json'})
44
+ end
45
+ end
46
+ end
47
+
48
+
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foy::API::Client::Base do
4
+ describe "#put_project_packages" do
5
+ subject do
6
+ Foy::API::Client::Base.new 'base'
7
+ end
8
+
9
+ let(:project_id) do
10
+ "321"
11
+ end
12
+
13
+ let(:data) do
14
+ [
15
+ {name: 'rest-client', version: '1.0.1'},
16
+ {name: 'rspec', version: '2.0.0'}
17
+ ]
18
+ end
19
+
20
+ let(:data_json) do
21
+ data.to_json
22
+ end
23
+
24
+ before do
25
+ stub_request(:put, /.*/).
26
+ to_return(status: 200)
27
+ end
28
+
29
+ it "calls put /v1/projects/:id/packages.json?system=rubygems" do
30
+ subject.put_project_packages(project_id: project_id, packages: data, system: 'rubygems')
31
+ WebMock.should have_requested(:put, "base/v1/projects/321/packages.json").with(query: {system: "rubygems"})
32
+ end
33
+
34
+ it "sends data as json" do
35
+ subject.put_project_packages(project_id: project_id, packages: data, system: 'rubygems')
36
+ WebMock.should have_requested(:put, /.*/).
37
+ with(body: {packages: data}.to_json)
38
+ end
39
+
40
+ it "indicates content as json" do
41
+ subject.put_project_packages(project_id: project_id, packages: data, system: 'rubygems')
42
+ WebMock.should have_requested(:put, /.*/).
43
+ with(headers: {"Content-Type" => 'application/json'})
44
+ end
45
+ end
46
+ end
47
+
@@ -0,0 +1,9 @@
1
+ RSpec.configure do |config|
2
+ config.treat_symbols_as_metadata_keys_with_true_values = true
3
+ config.run_all_when_everything_filtered = true
4
+ config.filter_run :focus
5
+ config.order = 'random'
6
+ end
7
+
8
+ require 'foy_api_client'
9
+ require 'webmock/rspec'
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foy_api_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Roberto Soares
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.14.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.14.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.17.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.17.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.7
55
+ description: FoY API Client
56
+ email:
57
+ - contact@robertosoares.me
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .ruby-gemset
64
+ - .ruby-version
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - foy-api-client.gemspec
70
+ - lib/foy_api_client.rb
71
+ - lib/foy_api_client/version.rb
72
+ - spec/get_packages_spec.rb
73
+ - spec/get_projects_spec.rb
74
+ - spec/put_packages_spec.rb
75
+ - spec/put_project_packages_spec.rb
76
+ - spec/spec_helper.rb
77
+ homepage: ''
78
+ licenses: []
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: FoY API Client
100
+ test_files:
101
+ - spec/get_packages_spec.rb
102
+ - spec/get_projects_spec.rb
103
+ - spec/put_packages_spec.rb
104
+ - spec/put_project_packages_spec.rb
105
+ - spec/spec_helper.rb