Module: Transifex

Defined in:
lib/tx-ruby/project.rb,
lib/tx-ruby.rb,
lib/tx-ruby/json.rb,
lib/tx-ruby/errors.rb,
lib/tx-ruby/formats.rb,
lib/tx-ruby/version.rb,
lib/tx-ruby/language.rb,
lib/tx-ruby/projects.rb,
lib/tx-ruby/resource.rb,
lib/tx-ruby/languages.rb,
lib/tx-ruby/resources.rb,
lib/tx-ruby/crud_requests.rb,
lib/tx-ruby/resource_components/stats.rb,
lib/tx-ruby/resource_components/source.rb,
lib/tx-ruby/project_components/language.rb,
lib/tx-ruby/resource_components/content.rb,
lib/tx-ruby/project_components/languages.rb,
lib/tx-ruby/resource_components/translation.rb,
lib/tx-ruby/project_components/language_components/reviewers.rb,
lib/tx-ruby/resource_components/translation_components/string.rb,
lib/tx-ruby/project_components/language_components/translators.rb,
lib/tx-ruby/resource_components/translation_components/strings.rb,
lib/tx-ruby/project_components/language_components/coordinators.rb,
lib/tx-ruby/resource_components/translation_components/utilities.rb

Overview

Add a method add_resource to create a new resource for the project Add a method get_resources to fetch all the resources

Defined Under Namespace

Modules: CrudRequests, JSON, ProjectComponents, ResourceComponents Classes: Configuration, Error, Formats, Language, Languages, MissingParametersError, ParametersFormatError, Project, Projects, Resource, Resources, TransifexError

Constant Summary collapse

VERSION =
"0.0.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



44
45
46
# File 'lib/tx-ruby.rb', line 44

def configuration
  @configuration
end

Class Method Details

.build_request_url(url = '') ⇒ Object



52
53
54
# File 'lib/tx-ruby.rb', line 52

def self.build_request_url(url='')
  URI(self.configuration.root_url + url)    
end

.configure {|configuration| ... } ⇒ Object

Yields:



47
48
49
50
# File 'lib/tx-ruby.rb', line 47

def self.configure
  self.configuration ||= Configuration.new
  yield configuration
end

.query_api(method, url, params = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/tx-ruby.rb', line 56

def self.query_api(method, url, params={})
  uri = build_request_url(url)

  res = Net::HTTP.start(uri.host, 80) do |http|
    req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, request_headers)
    req.basic_auth self.configuration., self.configuration.client_secret
    begin
      req.body = Transifex::JSON.dump(params)
    rescue Encoding::UndefinedConversionError
      params[:content] = params[:content].force_encoding("utf-8")
      req.body = Transifex::JSON.dump(params) 
    end
    http.request req
  end

  begin
    data = Transifex::JSON.load(res.body.nil? ? '' : res.body)
  rescue
    data = res.body
  end

  unless (res.is_a? Net::HTTPOK) || (res.is_a? Net::HTTPCreated) || (res.is_a? Net::HTTPNoContent)
    error = TransifexError.new(uri, res.code, data)
    raise error
  end    

  data
end

.request_headersObject



85
86
87
88
89
90
91
# File 'lib/tx-ruby.rb', line 85

def self.request_headers    
  request_headers = {      
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'User-Agent' => "Transifex-interface-ruby/#{Transifex::VERSION}"
  }    
end