turrialba 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ba80369708d83bd8539d9d51c76fd418528246ec
4
+ data.tar.gz: 8025f54a03ad6cfbe1e15e528a5cebae01f30d24
5
+ SHA512:
6
+ metadata.gz: 73e9cdb64f83e0784e2f26c0033fd0323e7347e946048c7f8f864d8acc6d344e01df87d3ce7a22bc3a5bf7903a76baa338f6e80003206a3d1895401e45350321
7
+ data.tar.gz: 510abd0e07463f0aed8e5d8fc85ff6d16d487e2ca7cf6c669d3e5b62057f3f269e68022416ddde22069f97ca628f1537bf3a6943489ffd21a43e47d7884808b6
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in turrialba.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Fernando Valverde Arredondo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Turrialba
2
+
3
+ This is a small gem that wraps the Turrialba server API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'turrialba'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install turrialba
20
+
21
+ ## Usage
22
+
23
+ The api is available with the Client object:
24
+
25
+ ```ruby
26
+ client = Turrialba::Client.new
27
+ user = client.user(360962402) # Fetches a user by uid
28
+ ```
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fdoxyz/turrialba-gem.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "turrialba"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,89 @@
1
+ require 'memoizable'
2
+ require 'turrialba/null_object'
3
+
4
+ module Turrialba
5
+ class Base
6
+ include Memoizable
7
+ # @return [Hash]
8
+ attr_accessor :attrs
9
+ alias to_h attrs
10
+ alias to_hash to_h
11
+
12
+ class << self
13
+ # Define methods that retrieve the value from attributes
14
+ #
15
+ # @param attrs [Array, Symbol]
16
+ def attr_reader(*attrs)
17
+ attrs.each do |attr|
18
+ define_attribute_method(attr.to_s)
19
+ define_predicate_method(attr.to_s)
20
+ end
21
+ end
22
+
23
+ def predicate_attr_reader(*attrs)
24
+ attrs.each do |attr|
25
+ define_predicate_method(attr)
26
+ end
27
+ end
28
+
29
+ # Define object methods from attributes
30
+ #
31
+ # @param klass [Symbol]
32
+ # @param key1 [Symbol]
33
+ # @param key2 [Symbol]
34
+ def object_attr_reader(klass, key1, key2 = nil)
35
+ define_attribute_method(key1, klass, key2)
36
+ define_predicate_method(key1)
37
+ end
38
+
39
+ # Dynamically define a method for an attribute
40
+ #
41
+ # @param key1 [Symbol]
42
+ # @param klass [Symbol]
43
+ # @param key2 [Symbol]
44
+ def define_attribute_method(key1, klass = nil, key2 = nil)
45
+ define_method(key1) do
46
+ if attr_falsey_or_empty?(key1)
47
+ NullObject.new
48
+ else
49
+ klass.nil? ? @attrs[key1] : Twitter.const_get(klass).new(attrs_for_object(key1, key2))
50
+ end
51
+ end
52
+ memoize(key1)
53
+ end
54
+
55
+ # Dynamically define a predicate method for an attribute
56
+ #
57
+ # @param key1 [Symbol]
58
+ # @param key2 [Symbol]
59
+ def define_predicate_method(key1, key2 = key1)
60
+ define_method(:"#{key1}?") do
61
+ !attr_falsey_or_empty?(key2)
62
+ end
63
+ memoize(:"#{key1}?")
64
+ end
65
+ end
66
+
67
+ # Initializes a new object
68
+ #
69
+ # @param attrs [Hash]
70
+ # @return [Twitter::Base]
71
+ def initialize(attrs = {})
72
+ @attrs = attrs || {}
73
+ end
74
+
75
+ private
76
+ def attr_falsey_or_empty?(key)
77
+ !@attrs[key] || @attrs[key].respond_to?(:empty?) && @attrs[key].empty?
78
+ end
79
+
80
+ def attrs_for_object(key1, key2 = nil)
81
+ if key2.nil?
82
+ @attrs[key1]
83
+ else
84
+ attrs = @attrs.dup
85
+ attrs.delete(key1).merge(key2 => attrs)
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,81 @@
1
+ require 'HTTParty'
2
+
3
+ module Turrialba
4
+ class Client
5
+ include HTTParty
6
+ base_uri ENV['TURRIALBA_URL'] || 'http://localhost:3000'
7
+
8
+ def initialize(auth_token = 'hashlol')
9
+ @auth_header = { 'X-AUTH-TOKEN': auth_token }
10
+ end
11
+
12
+ def user(uid)
13
+ response = self.class.get("/user/#{uid}", headers: @auth_header)
14
+ User.new(response.parsed_response)
15
+ end
16
+
17
+ def put_user(hash)
18
+ uid = hash['uid'] || hash['id_str']
19
+ response = self.class.put("/user/#{uid}",
20
+ body: filter_user_params(hash),
21
+ headers: @auth_header)
22
+ User.new(response.parsed_response)
23
+ end
24
+
25
+ def next_possessed_user
26
+ response = self.class.get("/next_possessed_user", headers: @auth_header)
27
+ User.new(response.parsed_response)
28
+ end
29
+
30
+ def tweet(id_str)
31
+ response = self.class.get("/tweet/#{id_str}", headers: @auth_header)
32
+ Tweet.new(response.parsed_response)
33
+ end
34
+
35
+ def put_tweet(uid, hash)
36
+ response = self.class.put("/user/#{uid}/tweet/#{hash['id_str']}",
37
+ body: filter_tweet_params(hash),
38
+ headers: @auth_header)
39
+ Tweet.new(response.parsed_response)
40
+ end
41
+
42
+ def put_favorite(uid, id_str)
43
+ response = self.class.put("/user/#{uid}/favorite/#{id_str}",
44
+ headers: @auth_header)
45
+ response.code == 200
46
+ end
47
+
48
+ def put_retweet(uid, id_str)
49
+ response = self.class.put("/user/#{uid}/retweet/#{id_str}",
50
+ headers: @auth_header)
51
+ response.code == 200
52
+ end
53
+
54
+ def put_follower_connection(uid, follower_uid)
55
+ response = self.class.put("/user/#{uid}/follows/#{follower_uid}/",
56
+ headers: @auth_header)
57
+ response.code == 200
58
+ end
59
+
60
+ private
61
+ def filter_user_params(hash)
62
+ valid_params = ["screen_name", "name", "location", "description",
63
+ "website", "profile_link_color", "image_url", "banner_url",
64
+ "statuses_count", "favourites_count", "followers_count",
65
+ "friends_count", "listed_count", "protected", "verified", "studder",
66
+ "followers_with_studder", "follower_mean_studder",
67
+ "scrapping_queued_at", "scrapping_request_count", "scrapped_at",
68
+ "possessed_at", "possession_group", "queue_rate_pause",
69
+ "total_scrapping_request_count"]
70
+ hash.select {|k,v| valid_params.include?(k) }
71
+ end
72
+
73
+ def filter_tweet_params(hash)
74
+ valid_params = ["id_str", "text", "tweeted_at", "embedded_html",
75
+ "author_id", "in_reply_to_tweet_id", "scrapping_queued_at",
76
+ "scrapping_request_count", "scrapped_at", "favorite_count",
77
+ "retweet_count", "in_reply_to_user_id", "total_scrapping_request_count"]
78
+ hash.select {|k,v| valid_params.include?(k) }
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,52 @@
1
+ require 'naught'
2
+
3
+ module Turrialba
4
+ NullObject = Naught.build do |config|
5
+ include Comparable
6
+
7
+ config.black_hole
8
+ config.define_explicit_conversions
9
+ config.define_implicit_conversions
10
+ config.predicates_return false
11
+
12
+ def !
13
+ true
14
+ end
15
+
16
+ def respond_to?(*)
17
+ true
18
+ end
19
+
20
+ def instance_of?(klass)
21
+ raise(TypeError, 'class or module required') unless klass.is_a?(Class)
22
+ self.class == klass
23
+ end
24
+
25
+ def kind_of?(mod)
26
+ raise(TypeError, 'class or module required') unless mod.is_a?(Module)
27
+ self.class.ancestors.include?(mod)
28
+ end
29
+
30
+ alias_method :is_a?, :kind_of?
31
+
32
+ def <=>(other)
33
+ if other.is_a?(self.class)
34
+ 0
35
+ else
36
+ -1
37
+ end
38
+ end
39
+
40
+ def nil?
41
+ true
42
+ end
43
+
44
+ def as_json(*)
45
+ 'null'
46
+ end
47
+
48
+ def to_json(*args)
49
+ nil.to_json(*args)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,10 @@
1
+ require 'turrialba/base'
2
+
3
+ module Turrialba
4
+ class Tweet < Turrialba::Base
5
+ attr_reader :id_str, :text, :tweeted_at, :embedded_html, :author_id,
6
+ :in_reply_to_tweet_id, :created_at, :updated_at, :scrapping_queued_at,
7
+ :scrapping_request_count, :scrapped_at, :favorite_count, :retweet_count,
8
+ :in_reply_to_user_id, :total_scrapping_request_count
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ require 'turrialba/base'
2
+
3
+ module Turrialba
4
+ class User < Turrialba::Base
5
+ attr_reader :id, :email, :uid, :secret, :provider, :created_at,
6
+ :updated_at, :token, :screen_name, :name, :location,
7
+ :description, :website, :profile_link_color, :image_url,
8
+ :banner_url, :statuses_count, :favourites_count,
9
+ :followers_count, :friends_count, :listed_count, :protected,
10
+ :verified, :default_profile_image, :default_profile, :studder,
11
+ :followers_with_studder, :follower_mean_studder,
12
+ :scrapping_queued_at, :scrapping_request_count, :scrapped_at,
13
+ :possessed_at, :possession_group, :queue_rate_pause,
14
+ :total_scrapping_request_count
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Turrialba
2
+ VERSION = "0.1.0"
3
+ end
data/lib/turrialba.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "turrialba/version"
2
+ require "turrialba/tweet"
3
+ require "turrialba/user"
4
+ require "turrialba/client"
data/turrialba.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'turrialba/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "turrialba"
8
+ spec.version = Turrialba::VERSION
9
+ spec.authors = ["Fernando Valverde Arredondo"]
10
+ spec.email = ["fdov88@gmail.com"]
11
+
12
+ spec.summary = "A Ruby interface to the Turrialba API."
13
+ spec.description = "A Ruby interface to the Turrialba API."
14
+ spec.homepage = "https://github.com/fdoxyz/turrialba-gem"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "httparty", "~> 0.14.0"
25
+ spec.add_dependency 'naught', '~> 1.0'
26
+ spec.add_dependency 'memoizable', '~> 0.4.0'
27
+ spec.add_dependency 'json', '~> 2.0.0'
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.14"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turrialba
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fernando Valverde Arredondo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.14.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.14.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: naught
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: memoizable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.14'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.14'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: A Ruby interface to the Turrialba API.
112
+ email:
113
+ - fdov88@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/turrialba.rb
128
+ - lib/turrialba/base.rb
129
+ - lib/turrialba/client.rb
130
+ - lib/turrialba/null_object.rb
131
+ - lib/turrialba/tweet.rb
132
+ - lib/turrialba/user.rb
133
+ - lib/turrialba/version.rb
134
+ - turrialba.gemspec
135
+ homepage: https://github.com/fdoxyz/turrialba-gem
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.6.10
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: A Ruby interface to the Turrialba API.
159
+ test_files: []