froyo_api 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5259da9ce703ca15b498a860b945765cea4305ae
4
+ data.tar.gz: b51f0d7683a980b71e3675716639e8b88e16dadd
5
+ SHA512:
6
+ metadata.gz: 2f11196a630b00ef611e51c456dc9dc424263d8afe0baad766793cfb11de68f6b9f0fe842d0c0b73d13a7c6a6e350aac7fa8566610a2b6280bef579639da9f05
7
+ data.tar.gz: befbfb84ddd17d51dd8c17c75f1041c3ddd2a9fb5a1815a282b84a21944ce2a4df1a706209a59ab46105c244f7d265d8c2d602396220a0379c82dc9fa854ef08
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format=documentation
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Maciej Małecki
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
+ # FroyoApi
2
+
3
+ Ruby gem for http://api.froyo.io
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'froyo_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install froyo_api
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/froyo_api/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 a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/froyo_api.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'froyo_api/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'froyo_api'
7
+ spec.version = FroyoApi::VERSION
8
+ spec.authors = ['Maciej Małecki']
9
+ spec.email = ['smt116@gmail.com']
10
+ spec.summary = %q{Ruby gem for http://api.froyo.io}
11
+ spec.description = %q{}
12
+ spec.homepage = ''
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{^(spec)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_development_dependency 'rspec'
23
+ end
@@ -0,0 +1,29 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+
4
+ module FroyoApi
5
+ class Client
6
+ def request(path)
7
+ options = params(path)
8
+ RestClient::Request.execute(options) do |response, request|
9
+ JSON.parse(response.body)
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def headers
16
+ {
17
+ accept: 'application/vnd.collection.doc+json'
18
+ }
19
+ end
20
+
21
+ def params(path)
22
+ {
23
+ method: :get,
24
+ url: "#{FroyoApi::URL}/#{path}",
25
+ headers: headers
26
+ }
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ module FroyoApi
2
+ class Name < Client
3
+ attr_reader :gender, :fullname, :firstname, :lastname
4
+
5
+ def initialize(gender = 'm')
6
+ @gender = gender
7
+ @fullname = attributes['fullname']
8
+ @firstname = attributes['firstname']
9
+ @lastname = attributes['lastname']
10
+ end
11
+
12
+ def attributes
13
+ @attributes ||= generate
14
+ end
15
+
16
+ private
17
+
18
+ def path
19
+ "names?gender=#{gender}"
20
+ end
21
+
22
+ def generate
23
+ request(path)['attributes']
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ module FroyoApi
2
+ class Password < Client
3
+ attr_reader :length, :password
4
+
5
+ def initialize(length = 8)
6
+ @length = length
7
+ @password = generate
8
+ end
9
+
10
+ private
11
+
12
+ def path
13
+ "pwd?length=#{length}"
14
+ end
15
+
16
+ def generate
17
+ request(path)['attributes']['password']
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,58 @@
1
+ require 'uri'
2
+
3
+ module FroyoApi
4
+ class Photo < Client
5
+ attr_reader :href, :type
6
+
7
+ def initialize
8
+ @href = attributes['href']
9
+ @type = attributes['type']
10
+ end
11
+
12
+ def filename
13
+ @filename ||= begin
14
+ uri = URI.parse(href)
15
+ File.basename(uri.path)
16
+ end
17
+ end
18
+
19
+ def download(directory = '.')
20
+ file = File.join(directory, filename)
21
+
22
+ File.open(file, 'wb') do |out|
23
+ process_response = lambda do |response|
24
+ response.read_body do |chunk|
25
+ out.write(chunk)
26
+ end
27
+ end
28
+
29
+ options = {
30
+ url: href,
31
+ method: :get,
32
+ block_response: process_response,
33
+ headers: {
34
+ accept: type
35
+ }
36
+ }
37
+
38
+ RestClient::Request.execute(options)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def attributes
45
+ @attributes ||= fetch
46
+ end
47
+
48
+ private
49
+
50
+ def path
51
+ "apod"
52
+ end
53
+
54
+ def fetch
55
+ request(path)['links']['enclosure'].first
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module FroyoApi
2
+ VERSION = '1.0.0'
3
+ end
data/lib/froyo_api.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'froyo_api/version'
2
+ require './lib/froyo_api/client'
3
+ require './lib/froyo_api/password'
4
+ require './lib/froyo_api/name'
5
+ require './lib/froyo_api/photo'
6
+
7
+ module FroyoApi
8
+ URL = 'http://api.froyo.io'
9
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe FroyoApi::Client do
4
+ describe '.request' do
5
+ let(:client) { FroyoApi::Client.new }
6
+
7
+ before do
8
+ allow(RestClient::Request).
9
+ to receive(:execute).
10
+ with(options).
11
+ and_return({test: 'ok'})
12
+ end
13
+
14
+ it { expect(client.request('test')).to eq({test: 'ok'}) }
15
+
16
+ private
17
+
18
+ def options
19
+ {
20
+ method: :get,
21
+ url: "http://api.froyo.io/test",
22
+ headers: {
23
+ accept: "application/vnd.collection.doc+json"
24
+ }
25
+ }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe FroyoApi::Name do
4
+ let(:name) { FroyoApi::Name.new }
5
+ let(:client) { FroyoApi::Client.new }
6
+
7
+ before do
8
+ allow(client).to receive(:request)
9
+ allow(RestClient::Request).to receive(:execute).and_return({
10
+ 'version' => '1.0',
11
+ 'attributes' => {
12
+ 'fullname' => 'Leo King',
13
+ 'firstname' => 'Leo',
14
+ 'lastname' => 'King'
15
+ },
16
+ 'links' => {
17
+ 'home' => [{
18
+ 'href' => 'http://api.froyo.io/'
19
+ }],
20
+ 'profile' => [{
21
+ 'href'=>'http://api.froyo.io/profiles/pwd'
22
+ }]
23
+ }
24
+ })
25
+ end
26
+
27
+ context '.gender' do
28
+ context 'by default' do
29
+ it { expect(name.gender).to eq('m') }
30
+ end
31
+
32
+ context 'when initialized with "k"' do
33
+ let(:name) { FroyoApi::Name.new('k') }
34
+
35
+ it { expect(name.gender).to eq('k') }
36
+ end
37
+ end
38
+
39
+ describe '.attributes' do
40
+ it { expect(name.attributes).to eq({
41
+ 'fullname' => 'Leo King',
42
+ 'firstname' => 'Leo',
43
+ 'lastname' => 'King'
44
+ })}
45
+ end
46
+
47
+ describe '.fullname' do
48
+ it { expect(name.fullname).to eq('Leo King') }
49
+ end
50
+
51
+ describe '.firstname' do
52
+ it { expect(name.firstname).to eq('Leo') }
53
+ end
54
+
55
+ describe '.lastname' do
56
+ it { expect(name.lastname).to eq('King') }
57
+ end
58
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe FroyoApi::Password do
4
+ let(:password) { FroyoApi::Password.new }
5
+ let(:client) { FroyoApi::Client.new }
6
+
7
+ before do
8
+ allow(client).to receive(:request)
9
+ allow(RestClient::Request).to receive(:execute).and_return({
10
+ "version" => "1.0",
11
+ "attributes" => {
12
+ "password" => "wroweste"
13
+ },
14
+ "links" => {
15
+ "home" => [{
16
+ "href" => "http://api.froyo.io/"
17
+ }],
18
+ "profile" => [{
19
+ "href"=>"http://api.froyo.io/profiles/pwd"
20
+ }]
21
+ }
22
+ })
23
+ end
24
+
25
+ context '.length' do
26
+ context 'by default' do
27
+ it { expect(password.length).to eq(8) }
28
+ end
29
+
30
+ context 'when initialized with length 12' do
31
+ let(:password) { FroyoApi::Password.new(12) }
32
+ it { expect(password.length).to eq(12) }
33
+ end
34
+ end
35
+
36
+ describe '.new' do
37
+ subject { password }
38
+
39
+ it { expect(subject.password).to eq('wroweste') }
40
+
41
+ context 'length of generated password' do
42
+ it { expect(subject.password.length).to eq(8) }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe FroyoApi::Photo do
4
+ let(:photo) { FroyoApi::Photo.new }
5
+ let(:client) { FroyoApi::Client.new }
6
+
7
+ before do
8
+ allow(client).to receive(:request)
9
+ allow(RestClient::Request).to receive(:execute).and_return({
10
+ 'version' => '1.0',
11
+ 'attributes' => {
12
+ 'title' => 'Example title'
13
+ },
14
+ 'links' => {
15
+ 'home' => [{
16
+ 'href' => 'http://api.froyo.io/'
17
+ }],
18
+ 'profile' => [{
19
+ 'href' => 'http://example.com/profile'
20
+ }],
21
+ 'distributor' => [{
22
+ 'href' => 'http://example.com/test',
23
+ 'title' => 'Example'
24
+ }],
25
+ 'enclosure' => [{
26
+ 'href' => 'http://example.com/test.jpg',
27
+ 'type' => 'image/jpeg'
28
+ }]
29
+ }
30
+ })
31
+ end
32
+
33
+ describe '.href' do
34
+ it { expect(photo.href).to eq('http://example.com/test.jpg') }
35
+ end
36
+
37
+ describe '.type' do
38
+ it { expect(photo.type).to eq('image/jpeg') }
39
+ end
40
+
41
+ describe '.filename' do
42
+ it { expect(photo.filename).to eq('test.jpg') }
43
+ end
44
+
45
+ describe '.download' do
46
+ before do
47
+ allow(RestClient::Request).
48
+ to receive(:execute).
49
+ with({
50
+ url: 'http://example.com/test.jpg',
51
+ method: :get,
52
+ block_response: nil,
53
+ headers: {
54
+ accept: 'image/jpeg'
55
+ }
56
+ })
57
+ end
58
+
59
+ context 'directory' do
60
+ context 'by default' do
61
+ it 'should eq ./test.jpg' do
62
+ expect(File).to receive(:open).with('./test.jpg', anything)
63
+ photo.download
64
+ end
65
+ end
66
+
67
+ context 'when directory argument is present' do
68
+ it 'should eq /tmp/test.jpg' do
69
+ expect(File).to receive(:open).with('/tmp/test.jpg', anything)
70
+ photo.download('/tmp')
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe FroyoApi do
4
+ describe '::URL' do
5
+ it { expect(FroyoApi::URL).to be_a(String) }
6
+ end
7
+
8
+ describe '::VERSION' do
9
+ it { expect(FroyoApi::VERSION).to be_a(String) }
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'froyo_api'
3
+
4
+ RSpec.configure do |config|
5
+ config.disable_monkey_patching!
6
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: froyo_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Maciej Małecki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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
+ - smt116@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - froyo_api.gemspec
69
+ - lib/froyo_api.rb
70
+ - lib/froyo_api/client.rb
71
+ - lib/froyo_api/name.rb
72
+ - lib/froyo_api/password.rb
73
+ - lib/froyo_api/photo.rb
74
+ - lib/froyo_api/version.rb
75
+ - spec/froyo_api/client_spec.rb
76
+ - spec/froyo_api/name_spec.rb
77
+ - spec/froyo_api/password_spec.rb
78
+ - spec/froyo_api/photo_spec.rb
79
+ - spec/froyo_api_spec.rb
80
+ - spec/spec_helper.rb
81
+ homepage: ''
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.4.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Ruby gem for http://api.froyo.io
105
+ test_files:
106
+ - spec/froyo_api/client_spec.rb
107
+ - spec/froyo_api/name_spec.rb
108
+ - spec/froyo_api/password_spec.rb
109
+ - spec/froyo_api/photo_spec.rb
110
+ - spec/froyo_api_spec.rb
111
+ - spec/spec_helper.rb